I'm developing an application in WPF and when I populate the datagrid via code it returns the duplicate value. I'm using Entity Framework.
XAMLCode
<DataGridx:Name="dataLocal" Margin="10,111,11,10" IsReadOnly="True" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" Header="ID" Visibility="Hidden"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding CidadeInicial}" Header="Cidade Inicial"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding CidadeDestino}" Header="Cidade Destino"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Carga}" Header="Carga"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Kmrodado}" Header="KM Rodado"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Status}" Header="Status"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
C # code
private void preencheDGV()
{
//this.DataContext = local.dadosLocais.Local;
dataLocal.ItemsSource = local.dadosLocais.Select(x => new
{
x.ID,
x.CidadeInicial,
x.CidadeDestino,
x.Carga,
x.Kmrodado,
x.Status
}).ToList();
}
If you have a question,