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.