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 に答える