Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Cell value update check
posted

Hi,

 I have a column which is of type decimal. now when the user enters a value in that cell and exits that i need to perform a validation to see that a subtraction of  value entered with another is greater than zero and if not then raise an error and let the focus be there in that cell.

 I could do this using the cell change event but i will end up performing the calcuation on each key change. is there any other way of doing this usign the before cell update or before exit mode events...

 Cheers

Rajesh

  • 735
    posted

    Yea, you can use the BeforeCellUpdate event. 

     private void MyGrid_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)

    {
        decimal val1 = (decimal)e.NewValue;
        decimal val2 = (decimal)e.Cell.Row.Cells["Column1"].Value;
     
        if (val2 - val1 <= 0)
        {
            // Raise error
            // Cancel update
            e.Cancel = true;
        }
    }

    By default, when you cancel the update event, the cell's value will revert back to the old one. To keep the the new value and retain focus to the cell, change the grid's RowUpdateCancelAction property to RetainDataAndActivation.