Hello Fish,
The provided information is greatly appreciated. I suppose that you want to make some data validation and you use the RowFormatting event. Actually, this is the expected behavior of using the event when validation fails, you are not allowed to close the form. Thus, it is guaranteed that all cells are valid.
If you want to have data validation when adding a new row and be able to close the form I can suggest you to use the UserAddingRow event which will fire for the new rows that are going to be added. Calling the MasterView.TableAddNewRow.CancelAddNewRow method will allow you to discard the changes in the new row and close the form. You can use the CellValidating event for the rows that contain data. The main difference with the RowValidating event is that the cell editor will be kept active until the user enters a valid value if the CellValidating event is cancelled. However, the RowValidating event allows you to commit invalid values to the DataBoundItem and the validation will be performed whenever you want to leave this row. That is why the CellValidating event may be more appropriate if you want to ensure that no invalid data is submitted to the data objects. It allows you to reject the editor's value as if the Escape key is pressed by calling the GridViewElement.CancelEdit method while the grid is in edit mode. Could you please give that approach a try and see how it works for you?
However, if you want to use the RowValidating event please take a look at the following code snippet:
bool close = true;
private void RadForm1_FormClosing(object sender, FormClosingEventArgs e)
{
if (close)
{
close = false;
radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
this.Close();
}
}
private void RadGridView1_RowValidating(object sender, RowValidatingEventArgs e)
{
if (e.Row.Cells["FirstName"].Value + "" == "")
{
e.Cancel = true;
}
}
Feel free to use this approach which suits your requirements best.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Nadya
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.