How can I prevent add new row's adding empty record?

Hi

How can I prevent add new row's adding empty record?



1 Reply

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

Hi Eren, 

Thanks for using Syncfusion products. 

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 event. 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