2012-07-01 5 views
0

DataGrid에 몇 가지 문제가 있습니다. DataGridCanUserAddRows으로 설정하면 DataGrid 하단에 새 검은 색 행이 있지만이 행은 예기치 않은 동작을합니다. 새 행을 클리핑하고 다른 셀에 포커스를 전달하면 행이 비어 있어도 생성되므로 . 행이 비어 있으면 새 항목을 만들지 말고 동작을 변경하고 싶습니다. 그러나 RowEditEndinge.Cancel=true으로 설정하면 NewItemPlaceHolder이 사라지고 그 이후로 아무 행이나 추가 할 수 없습니다. 어떤 신체가이 문제에 대한 해답을 찾았습니까?잘못된 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); 
} 
+0

케어를 새로 고쳐을 할 수있는 방법을 발견? –

+0

"DeferRefresh가 AddItem 또는 NewItem 트랜잭션에 허용되지 않습니다."예외가 발생하면 New를 취소합니다. – Nandhi

+0

이 솔루션을 사용하는 것이 좋습니다! http://stackoverflow.com/a/42763784/973344 –

답변

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; 
관련 문제