Objects are saved (inserted or updated) when the user leaves the line that he edited. Moving to another cell on the same line updates the corresponding property by means of data binding, but so far does not signal the model (or data access level). The only useful event is DataGrid.RowEditEnding. This fires just before the modified line is executed.
Xaml
<DataGrid ... RowEditEnding="MyDataGrid_RowEditEnding"> </DataGrid>
Code for
private void MyDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { // Only act on Commit if (e.EditAction == DataGridEditAction.Commit) { var newItem = e.Row.DataContext as MyDataboundType; if (newItem is NOT in my bound collection) ... handle insertion... } }
All credits for this solution go to Diederik Krolls ( Original post ). My respect.
source share