I need to be able to update values of a dataset once a cell loses focus from editing. I know when the cell loses focus (CellEditEnding), but problem is, the actual updating of it's context item does not occur till focus on that row actually occurs. This becomes a huge issue when there is only one item left, since it may never lose focus.
How do I make sure that each time a column edit is complete (CellEditEnding), the actual context for that row is updated at that point (not just when the row loses focus)
Thanks in advance!
I met a similar problem, I have a DataGrid row that contains 5 columns. The data from the 5 columns will be updated in source only after the entire datagrid row has lost focus.
After some search, I found an easy way to do it. That is to add "UpdateSourceTrigger=LostFocus" in your databinding in the cell.
For example:
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Name"
ItemsSource="{Binding Path=MyDataSets}"
SelectedValue="{Binding Path=DataSelected, UpdateSourceTrigger=LostFocus}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
This will do the trick, so when each of the cell lost focus, instead of the entire row, the data from the cell will update the source immediately.
You can use DataGrid.CommitEdit
from your DataGrid.CellEditEnding
handler, being sure to handle reentrancy.
Here's a blog article that describes the technique:
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