To reproduce:
- Add a RadGridView and a button to a blank form.
- Subscribe to CellValidating event from the grid and set the cancel property of the CellValidatingEventArgs to true upon some condition.
- Add click event handler for the button and print a message in it.
- Start the application and enter some invalid data in the grid cell, then click the button.
- The code from the button's event handler is executed.
Workaround use a flag to determine when to execute the corresponding button code:
bool validating = false;
void radGridView1_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
{
if (e.Value.ToString().Length < 5)
{
e.Cancel = true;
validating = true;
e.Row.ErrorText = "Validation error!";
}
else
{
validating = false;
}
}
private void radButton1_Click(object sender, EventArgs e)
{
if (!validating)
{
Debug.WriteLine("Executed");
}
}