0
votes

I have a problem adding a checkbox-column to a WPF-datagrid.

  1. I create a datatable with 8 columns and fill it using sql.
  2. I bind the datatable to the WPF-datagrid using ItemsSource like:

    XAML:

    <DataGrid x:Name="dgOPListEntries" Grid.Row="1" Grid.ColumnSpan="2" Margin="5" ItemsSource="{Binding}" AutoGenerateColumns="True"></DataGrid>

    CodeBehind:

    dgOPListEntries.ItemsSource = dtOPListEntries.DefaultView;

So far, this works fine.

I now want to add a checkbox-column to the datagrid where I can select some rows. (The selected rows will then be updated on the sql server.)

Any help is appreciated.

1

1 Answers

2
votes

If what you want is just to select some rows, you can use DataGrid.SelectionMode and DataGrid.SelectionUnit properties set to DataGridSelectionMode.Extended and DataGridSelectionUnit.FullRow, respectively.

In addition, DataGrid creates checkbox column automatically for data of type bool, if you can add a field to your items source.