DataGrid
我遇到了一些问题。当DataGrid
设置为CanUserAddRows
时,新的黑色行位于DataGrid
的底部,但这些行有意外的行为,因为如果我只是clik新行并传递焦点对于另一个单元格,即使该行为空,也会创建该行。如果行为空,我想通过非常改变行为,避免创建新项目,但如果事件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);
}
答案 0 :(得分:3)
我刚刚通过刷新CanUserAddRows属性找到了一种方法
bool canUserAddRows = Datagrid.CanUserAddRows;
//Makes the refresh for CanUserAddRows because when cancel the new adding then collapse the NewPlaceHolder item
Datagrid.CanUserAddRows = !canUserAddRows;
Datagrid.CanUserAddRows = canUserAddRows;