I have this tiny little issue with the datagrid.
In my grid I have a checkbox column which is the only editable column.
The behavior that I'm looking for is for the datagrid to update i's datasource as soon as the status of the checkbox changes. So user checks/unchecks the box > underlying datatable gets updated.
The default behavior seems to update the source when the row loses focus requiring the user to press a key or click on some other control to save the changes.
How can I change this behavior?
I don't see any property for the datagrid that could do this and no CheckChanged event for DataGridCheckBoxColumn.
You need the UpdateSourceTrigger
property on the binding of the column. Here is a quick example, you can flesh it out and fill in the blanks:
<DataGrid x:Name="someGrid">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding SomeProperty, UpdateSourceTrigger=PropertyChanged}" />
</DataGrid.Columns>
</DataGrid>
The DataGrid itself sets the UpdateSourceTrigger for all columns (aside from template columns) to be LostFocus and this can't be overridden. Hence the need to use template columns with a checkbox template.
EDIT: This is just one in a long list of silly gotchas around DataGrid columns. More are outlined here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With