Reputation: 4371
I'm dealing with the WPF DataGrid. I need it to show the empty row for new items when I start editing a new row. I want this because sometimes the user just clicks outside of the datagrid without completing the information of the row.
A solution I tried was commiting row changes when the grid lost focus BUT the event is kind of wrong because it loses focus to any control INSIDE itself.
How do I commit row changes when the data grid lose focus?
Thanks!
Upvotes: 0
Views: 762
Reputation: 4852
I hope the below code will help.
private void grdEmp_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (!isManualEditCommit)
{
isManualEditCommit = true;
DataGrid grid = (DataGrid)sender;
grid.CommitEdit(DataGridEditingUnit.Row, true);
isManualEditCommit = false;
}
}
Upvotes: 1
Reputation: 2686
You might take a look at this answer. The specifics are different, but basically, it sets up a behavior to commit changes when the DataGrid loses focus. I was able to tweak this a bit to resolve issues I was having.
Upvotes: 0