Note that there are some explanatory texts on larger screens.

plurals
  1. POComboboxes in GridView are synchronized instead of bound to the value from the database
    primarykey
    data
    text
    <p>I have tried to set up combo boxes in the gridview but all the combo boxes have the same value in them instead of the value from the database. I am using entity framework and WPF. There is a parent child relationship between two tables but the source for the combo box is a separate table with names and IDs for tags. I have been looking all day. Hopefully this won't be too easy to solve.</p> <p>The "Tag" Column displays the combo box. The Column "Tag ID" displays the value from the database. When I display the data the TagID Changes in diffrent rows but the Tag column is the same (the first choice) in all the rows. When I change one combo box they all change. I can't see where they are hooked together. Any assistance you can provide would be appreciated. (Buler?)</p> <p>Here is the XAML</p> <pre><code>&lt;Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="372" Width="675" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:TagFinanceWPF"&gt; &lt;Window.Resources&gt; &lt;CollectionViewSource x:Key="TransactionsViewSource" d:DesignSource="{d:DesignInstance my:Transaction, CreateList=True}" /&gt; &lt;CollectionViewSource x:Key="TransactionsTransactionTagsViewSource" Source="{Binding Path=TransactionTags, Source={StaticResource TransactionsViewSource}}" /&gt; &lt;CollectionViewSource x:Key="TagLookup" /&gt; &lt;/Window.Resources&gt; &lt;Grid DataContext="{StaticResource TransactionsViewSource}"&gt; &lt;ListView ItemsSource="{Binding Source={StaticResource TransactionsTransactionTagsViewSource}}" Margin="12" Name="TransactionTagsListView" SelectionMode="Single"&gt; &lt;ListView.ItemContainerStyle&gt; &lt;Style&gt; &lt;Setter Property="Control.HorizontalContentAlignment" Value="Stretch" /&gt; &lt;Setter Property="Control.VerticalContentAlignment" Value="Stretch" /&gt; &lt;/Style&gt; &lt;/ListView.ItemContainerStyle&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn x:Name="TransactionIDColumn1" Header="Transaction ID" Width="80"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Label Content="{Binding Path=TransactionID}" Margin="6,-1,-6,-1" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn x:Name="TagIDColumn" Header="Tag" Width="80"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox Margin="-6,-1" ItemsSource="{Binding Source={StaticResource TagLookup}}" DisplayMemberPath="TagName" SelectedValuePath="TagID" SelectedValue="{Binding TagID}" IsReadOnly="True"&gt; &lt;/ComboBox&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn x:Name="TagIDColumn2" Header="Tag ID" Width="80"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Label Content="{Binding Path=TagID}" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>The VB code is:</p> <pre><code>Class MainWindow Dim BentleyvideoEntities As TagFinanceWPF.bentleyvideoEntities = New TagFinanceWPF.bentleyvideoEntities() Private Function GetTransactionsQuery(ByVal BentleyvideoEntities As TagFinanceWPF.bentleyvideoEntities) As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction) Dim TransactionsQuery As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction) = BentleyvideoEntities.Transactions 'Update the query to include TransactionTags data in Transactions. You can modify this code as needed. TransactionsQuery = TransactionsQuery.Include("TransactionTags") 'Returns an ObjectQuery. Return TransactionsQuery End Function Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded 'Load data into Transactions. You can modify this code as needed. Dim TransactionsViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TransactionsViewSource"), System.Windows.Data.CollectionViewSource) Dim TransactionsQuery As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction) = Me.GetTransactionsQuery(BentleyvideoEntities) TransactionsViewSource.Source = TransactionsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly) 'Load data into Tags. You can modify this code as needed. Dim customerList = From c In BentleyvideoEntities.Tags _ Order By c.TagName Dim custSource = CType(Me.FindResource("TagLookup"), CollectionViewSource) custSource.Source = customerList.ToList() End Sub </code></pre> <p>End Class</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload