How to Cancel DataGrid SelectionChange - MVVM #17971
-
Hi Community,
In the input fileds, the SelectedPerson stays as expected unchanged, but the DataGrid doesn't care at all and changes its selection. What would be the correct approach to get the expected behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Are you using the cell/row editing functionality of DataGrid? ie: DataGrid dg;
dg.IsReadOnly = false;
dg.RowEditEnding += (s, e) =>
{
e.Cancel = (e.Row.DataContext as MyViewModelItem).HasChangedButNotSaved;
} I think editing modus influences selecting. You can also use CellEditEnding. |
Beta Was this translation helpful? Give feedback.
Probably because the datagrid is not in editing modus here. I see you selecting the 3rd row. And then change value in a textbox outside of the datagrid. Editing that textbox will not set the datagrid into edit modus, and so event RowEditEnding will not fire (debug or trace that handler to check).
You can set the datagrid into edit modus manually using BeginEdit() (and probably manually end editing, CommitEdit() or CancelEdit()).