1

我有一些问题DataGrid。当DataGrid设置为CanUserAddRows新的黑色行时,DataGrid这些行会出现意外行为,因为如果我只是单击新行并将焦点传递给另一个单元格,即使该行为空,也会创建该行。如果该行为空,我想通过改变行为来避免创建新项目,但如果在RowEditEnding我设置的情况下e.Cancel=true,那么NewItemPlaceHolder从那时起我将无法添加任何行。有没有人找到这些问题的答案?

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);
}
4

1 回答 1

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;
于 2012-07-06T19:52:40.127 回答