We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Canceling row edit and checking empty columns

Hello!


How to check if certain cells are empty before pressing save button?

3 Replies

FP Farjana Parveen Ayubb Syncfusion Team August 28, 2019 02:41 AM

Hi Josip, 
 
Thank you for using Syncfusion controls. 
 
We have analyzed query, we suspect that you have to save the edited values of a row in your DataBase without empty values by using Save button. This can be achieve by using SelectedItem property in SfDataGrid, its contains the underlying object of the particular row data. So using that we can process and save the value in SfDataGrid. 
 
Please refer the below code example  
 
private void button1_Click(object sender, EventArgs e) 
{ 
    if (sfDataGrid.SelectedItem != null) 
    { 
        var orderInfo = (sfDataGrid.SelectedItem as OrderInfo); 
        if (!string.IsNullOrEmpty(orderInfo.Country) && 
            !string.IsNullOrEmpty(orderInfo.CustomerID) && 
            !string.IsNullOrEmpty(orderInfo.CustomerName)) 
        { 
            // You can save the edit value here. 
        } 
    } 
} 
 
 
If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 
 
Regards,
Farjana Parveen A
 



JO Josip August 28, 2019 04:13 AM

In my case sfDataGrid has datasoruce DataTable. Each colum has Mapping name.
What I want to do is if I press on save button, check certain cells are they empty or not or I'm I'm adding and row and when I leave this row, check certain cells if they are empty.


FP Farjana Parveen Ayubb Syncfusion Team August 29, 2019 02:09 AM

Hi Josip, 
 
Thank you for the update. 
 
We suspect that you need to add a new row without empty cell using AddNewRow in SfDataGrid, this can be achieved by using RowValidated event in SfDataGrid. 
 
Please refer the below code example 
 
sfDataGrid.RowValidating += SfDataGrid_RowValidating;  
 
private void SfDataGrid_RowValidating(object sender, Syncfusion.WinForms.DataGrid.Events.RowValidatingEventArgs e) 
{ 
    if (sfDataGrid.IsAddNewRowIndex(e.DataRow.RowIndex)) 
    { 
        var data = (e.DataRow.RowData as DataRowView).Row; 
        if (string.IsNullOrEmpty(data.ItemArray[0].ToString()) || string.IsNullOrEmpty(data.ItemArray[1].ToString()) || string.IsNullOrEmpty(data.ItemArray[2].ToString())) 
        { 
            e.ErrorMessage = "Records cannot be empty"; 
            e.IsValid = false; 
        } 
    } 
} 
 
 
If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 
 
Regards,
Farjana Parveen A
 


Loader.
Live Chat Icon For mobile
Up arrow icon