I am currently using a datagrid to either:
-Update a current value based on its previously existing serial number in the selected row.
-If the previous serial number doesn't exist in the database(basically an empty row), insert a new row into the database.
My current approach is using a RowEditEnding trigger to pull the previous serial number from the selected row before it was changed, and after I would like to use another trigger to read the updated data in the row after it has been changed to send the corresponding sql command to the server. What is the best event handler in a datagrid for this? Is there a better approach?
CodePudding user response:
You can do it in the same RowEditEnding function:
private bool _handle = true;
private void dataGridAddItem_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
var item = (MyRowClass)e.Row.DataContext;
var grid = (DataGrid)sender;
if (_handle)
{
//get your values before they changed here
_handle = false;
grid.CommitEdit();
//do whatever you need to do here (the values on item will change from before to after the CommitEdit
_handle = true;
}
}
If you don't use the _handle bool as shown above, you'll enter an infinite loop.