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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Canceling row edit and checking empty columns

Thread ID:

Created:

Updated:

Platform:

Replies:

146978 Aug 27,2019 01:09 PM UTC Aug 29,2019 10:09 AM UTC WinForms 3
loading
Tags: SfDataGrid
Josip
Asked On August 27, 2019 01:17 PM UTC

Hello!


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

Farjana Parveen Ayubb [Syncfusion]
Replied On August 28, 2019 10:41 AM UTC

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
 


Josip
Replied On August 28, 2019 12:13 PM UTC

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.

Farjana Parveen Ayubb [Syncfusion]
Replied On August 29, 2019 10:09 AM UTC

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
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon