C# WPF DataGrid.ItemsSource generates new Columns

Viewed 3753

I use a DataTable as source for my DataGrid:

  dt.Columns.Add("Update?", typeof(Boolean));
  dt.Columns.Add("Emulator", typeof(String));
  dt.Columns.Add("Path", typeof(String));

  ...      

  dataGrid1.ItemsSource = dt.DefaultView;

The XAML code to the DataGrid:

     <DataGrid  AutoGenerateColumns="True" Height="133" HorizontalAlignment="Left" Margin="0,81,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="688"  >
        <DataGrid.Columns>
            <DataGridCheckBoxColumn CanUserResize="False" Header="Update?" />
            <DataGridTextColumn CanUserResize="False" Header="Emulator" IsReadOnly="False"/>
            <DataGridTextColumn CanUserResize="False" Header="Path" IsReadOnly="False"/>
        </DataGrid.Columns>
    </DataGrid>

So if the DataTable is empty I got an empty DataGrid showing the three headers names.
If the DataTable contains items the DataGrid gets extra columns instead of filling the already existing ones.

enter image description here

What can I do that the DataGrid fills up its existing columns?

1 Answers
Related