I’m working with WPF and EF. I’m using a Datagrid to show information.
In my viewmodel, I’ve an ObservableCollection. This collection is the direct source of my DataGrid.
Here is the declaration of my DataGRid :
<DataGrid Margin="6" BorderBrush="Black" BorderThickness="1"
AutoGenerateColumns="False"
SelectionMode="Extended"
SelectionUnit="FullRow"
AlternatingRowBackground="Gainsboro"
AlternationCount="2"
Name="DataGridClientSpecs"
CanUserAddRows="False"
ItemsSource="{Binding ClientSpecifications}"
VerticalScrollBarVisibility="Auto" Height="500" >
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Wanted ?" Binding="{Binding Wanted}" />
<DataGridTextColumn Header="Product" Binding="{Binding ProductSpecification.ProductType}" />
<DataGridTextColumn Header="Conditionnement" Binding="{Binding ProductSpecification.ConditionnementType}" />
<DataGrid.Columns>
</DataGrid>
And I’ve 2 issues :
-
when I try to select a row, it always selects the first row.
-
some rows are duplicated.
When I bind the collection to a ListBox, I don’t have duplicate rows but the selection is still not working.
Hope someone can help me…
Cheers
Thomas
I solved my problem 🙂
It’s the fault of Entity Framework !
As it’s a list of new items (I mean they doesnt exist in the DB) so their ID’s are equal to 0 AND as I’m overwritting the Equals() method for this class and as I’m doing the comparison on the ID, the ID is always 0 so all items of my list are the same 🙂
Btw, it’s the same with all Control that show a list of items.
Problem Solved ! Hope it will help people.
Cheers
Thomas