How can i Control CollectionChanged event is finish

i need to do stuff after  (SfDataGrid.View as CollectionViewAdv).CollectionChanged event.
How can i control event is finish because i can't remove a row it's trow exception about 

The ObservableCollection can not be changed during the CollectionChanged event.

         if (isemptyrow)

            {

                dtgrid.View.Records.RemoveAt(emptyrowindex);
                isemptyrow = false
          }

1 Reply

AR Amal Raj U Syncfusion Team June 11, 2018 11:25 AM UTC

Hi Eren, 

Thanks for using Syncfusion products. 

ObservableCollection cannot be modified in the CollectionChanged event, since modifying the ObservableCollection in CollectionChanged is not thread safe and it is not supported in .NET framework.  

If you want to avoid adding the empty record through AddNewRow itself, then adding the new row can be avoided by validating the row in RowValidating row. Please refer to the code example and the sample in the following location. 

Code Example: 
sfDataGrid.RowValidating += SfDataGrid_RowValidating; 
 
private void SfDataGrid_RowValidating(object sender, Syncfusion.WinForms.DataGrid.Events.RowValidatingEventArgs e) 
{ 
    var id = (e.DataRow.RowData as DataRowView).Row[0]; 
    var value = id != null ? id.ToString() : string.Empty; 
 
    if (string.IsNullOrEmpty(value)) 
    { 
        e.ErrorMessage = "Employee ID cannot be null"; 
        e.IsValid = false; 
    } 
} 

Sample Location: 
 
Regards, 
Amal Raj U. 


Loader.
Up arrow icon