WPF Datagrid行编辑"ENDED";事件 [英] WPF Datagrid Row Editing "ENDED" event
问题描述
我知道WPF数据网格具有"RowEditEnding"事件,但是我需要在Row提交后触发该事件,以检查新添加的行是否重复并合并重复的行.我的数据网格的"CanUserAddRow"属性设置为True.
I know that WPF datagrid has "RowEditEnding" event , but I need to fire the event on after the Row has comitted to check if the newly added row is duplicated and merge the duplicated row. My datagrid has "CanUserAddRow" property set to True.
我正在使用EntityObservableCollection,它扩展了ObservableCollection来将我的实体与集合同步.因此,我考虑了OnCollectionChanged事件,但是一旦用户单击新项目占位符行,就会引发"InsertItem"事件,这意味着该对象仍然为空,并且我无法检查重复项.
I am using EntityObservableCollection that extends ObservableCollection to synchronize my entity with the collection. So, i considered OnCollectionChanged event, but the "InsertItem" event is raise once user click on the new item place holder row, which means the object is still empty and I cant check for duplicate.
反正我可以引发RowEditEnded事件吗?
Is there anyway that I can raise the RowEditEnded event?
谢谢...
推荐答案
private void dgrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (this.dgrid.SelectedItem != null)
{
(sender as DataGrid).RowEditEnding -=dgrid_RowEditEnding;
(sender as DataGrid).CommitEdit();
(sender as DataGrid).Items.Refresh();
(sender as DataGrid).RowEditEnding += dgrid_RowEditEnding;
}
else Return;
//then check if the newly added row is duplicated
}
这篇关于WPF Datagrid行编辑"ENDED";事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!