WPF DataGrid: can I cancel the change selection action?

I am currently dealing with the SelectionChanged event, but I would prefer to catch the eariler event, which will allow me to cancel the selection change.

Background:

I have two data grids, the bottom is a detail of the top. When the top changes change, I currently suggest the user save the changes. But if there are verification errors, I want to offer them the opportunity to undo the change of choice and correct these errors.

+4
source share
1 answer

You can try snapping the top grid ItemsSource a ICollectionView as follows.

 var items = CollectionViewSource.GetDefaultView(*your current bound collection* ); items.CurrentChanging += this.OnCurrentItemChanging; *your grid*.ItemsSource = items; 

Then inside OnCurrentItemChanging you can do e.Cancel = true , which will cancel the selection change.

+2
source

All Articles