Cancel edit cell on validation failed

4 posts, 1 answers
  1. masha reznik
    masha  reznik avatar
    17 posts
    Member since:
    Jan 2010

    Posted 12 Mar 2010 Link to this post

    Hello,
    how i can cancel edit cell (reset value) when validation is failed?

    Masha
  2. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 15 Mar 2010 Link to this post

    Hello masha reznik,

    You could use the CellValidating event to determine when validation has failed and cancel the edit:

    private void RadGridView_CellValidated(object sender, GridViewCellValidatedEventArgs e)
    {
        if (e.ValidationResult.ErrorMessage != null)
        {
            this.myGrid.CancelEdit(); 
        }
    }


    Best wishes,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Jeff
    Jeff avatar
    6 posts
    Member since:
    Jun 2016

    Posted 17 Nov 2016 in reply to Milan Link to this post

    Hi Milan,

    I'm using Telerik Gridview 2015.3.930.40 and the GridViewCellValidatedEventArgs seems to have changed to CellValidatedEventArgs and doesn't have the ValidationResult property.

     

    I want to cancel the edit and rollback to the old value. Should I do my validation and rollback in an other event that is raise before CellValidated and CellValidating?

  4. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 22 Nov 2016 Link to this post

    Hi Jeff,

    When the user tries to commit an edit, the first event that is raised is the CellValidating one. So, you can use it and implement your validation logic as demonstrated in the Validating help article. When a given value is considered as invalid, you can call the CancelEdit method of RadGridView.

    Hopefully, this helps.

    Regards,
    Stefan X1
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Back to Top