【发布时间】:2012-07-01 18:06:44
【问题描述】:
我对@987654322@ 有一些问题。当DataGrid 设置为CanUserAddRows 时,一个新的黑色行被放置在DataGrid 的底部,但是这些行有一个意外的行为,因为如果我只是单击新行并将焦点传递给另一个单元格,则该行是即使它是空的,也会创建。如果该行为空,我想通过改变行为来避免创建新项目,但如果在事件RowEditEnding 我设置了e.Cancel=true,那么NewItemPlaceHolder desapears 并且从那时起我无法添加任何行。有没有人找到这些问题的答案?
protected override void OnRowEditEnding(DataGridRowEditEndingEventArgs e)
{
if ((e.Row.Item as DataRowView).Row.ItemArray[0] == null || (e.Row.Item as DataRowView).Row.ItemArray[0].ToString() == String.Empty)
{
e.Cancel = true;
IEditableCollectionView collection = Items as IEditableCollectionView;
if (collection.IsAddingNew)
{
collection.CancelNew();
}
}
base.OnRowEditEnding(e);
}
【问题讨论】:
-
我取消 New,因为如果我不这样做,则会引发“AddItem 或 NewItem 事务不允许延迟刷新”的异常
-
我推荐使用这个解决方案! stackoverflow.com/a/42763784/973344