How to cancel an edit.

3 posts, 0 answers
  1. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 04 Mar 2011 Link to this post

    Hi,

    I have a grid with numeric data that can be edited by the user. If the user enters a non numeric value the edit should be cancelled and the cell value should revert to the original value (skipping validation). When the grid is bound to a DataTable I am able to do this using the CellValidating event as such:

    private void OnManualSplitPointsValidating(object sender, GridViewCellValidatingEventArgs e)
            {
                if (Helper.IsNumeric(e.NewValue) == false)
                {
                    var grid = (RadGridView) sender;
                    grid.CancelEdit();
                }
            }

    But when I apply this same code to a CSLA collection the line grid.CancelEdit() causes a row deletion. This may be a problem with the CSLA list but I wanted to check if there is a different way of reverting to the previous value (or if indeed this is supported at all).

    I am using the latest Beta and .NET 4.0.

    Cheers,
    Jose
  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 05 Mar 2011 Link to this post

    Hi Jose Simas,

     You can just set the cell as invalid. That way the user won't be able to complete the edit operation until the cell contains a valid value and the underlying data for the cell won't be modified.

    Kind regards,
    Yavor Georgiev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 06 Mar 2011 Link to this post

    Hi,

    I could indeed but I am being asked to revert to the previous value. As I said, it works just fine when the grid is bound to a DataTable but unfortunately it causes side effects when I call CancelEdit if it is bound to a CSLA collection. I post this thread to see if there was an alternate way of doing this.

    Cheers,
    Jose
Back to Top