Canceling row edit and checking empty columns
3 Replies
FP
Farjana Parveen Ayubb
Syncfusion Team
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
Farjana Parveen A
JO
Josip
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.
FP
Farjana Parveen Ayubb
Syncfusion Team
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
Farjana Parveen A
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JO Josip
- Aug 27, 2019 01:09 PM UTC
- Aug 29, 2019 10:09 AM UTC