1
I am developing an application in WPF and when I fill the datagrid via code it returns the duplicate value. I am using Entity Framework.
XAML
<DataGrid x: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>
Code C#
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();
}
Apart from this doubt, I have the following question: How to apply an Autosize in the Columns of this datagrid?
Thanks, super complete reply. It helped a lot
– Deivid Farias