Declined
Last Updated: 06 Feb 2018 06:40 by ADMIN
ADMIN
Dimitar
Created on: 12 May 2014 13:21
Category: GridView
Type: Bug Report
0
FIX. RadGridView - the CellValidating event does not prevent the user from clicking a button on the form when the cell contains invalid value.
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");
    }
}


1 comment
ADMIN
Ralitsa
Posted on: 06 Feb 2018 06:40
By default, the CellValidating event is fired when a cell is changed and not when one leaves the control. If you want to handle this case one should use the Validating event. If we want to handle this both events will be fired when one leaves the controls and the Validating event will depend on the CellValidating which is undesired.