开发者

WPF DataGrid: Can I cancel a change selection action?

开发者 https://www.devze.com 2023-01-18 15:35 出处:网络
Currently I\'m catching the SelectionChanged event, but I would prefer to catch an eariler event that will allow me to cancel the selection change.

Currently I'm catching the SelectionChanged event, but I would prefer to catch an eariler event that will allow me to cancel the selection change.

Background:

I have two data grids, the lower being a detail of the upper. When the upper changes, I currently prompt the user to save changes. But if there are validation errors, I w开发者_运维知识库ant to offer them the option to cancel the selection change and fix those errors.


You can try binding the upper grid's ItemsSource an ICollectionView as follows.

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消