I have researched this and am stumped: I have a WPF DataGrid, and using an MVVM model. I want to, under certain circumstances, prevent the ability to change a row in the DataGrid. I have researched this and have tried techniques like the one found here.
In practice, this works, however there is an undesirable 'flicker' (it selects the clicked row for a moment then goes back to the previous selection), while this is a close solution I wish there was a more elegant way such as preventing the row change at all in the first place.
I am surprised there is not a SelectionChanging or BeforeSelectionChanged so I could cancel the event from firing; and forcibly preventing the index change in my view model does not seem to make any difference.
How can I do this?
Thank you.
Pravesh Singh
24-Sep-2013Do you have a CellStyle on your datagrid? For me, the following worked:
xaml:
codebehind:
The point was that the SelectedCellsChanged event fired after the SelectionChanged event -- and in particular, that setting the SelectedItem does not correctly update the SelectedCells which are a read-only property, so more codebehind: