how to cancel row level edit event

2 posts, 0 answers
  1. Gavin
    Gavin avatar
    8 posts
    Member since:
    Mar 2013

    Posted 16 Jul 2014 Link to this post

    I am using telerik RadGridview 2013 Q3.  We have a N-Tier app, so I am saving the record per row instead of per cell.  I have a requirement from the business user mandating a confirmation dialog to be shown asking if the user wants to save the data when the user navigates away from the current editing row.  I tried to show the confirmation dialog at the roweditended event, but when the user clicks on No, the row's edit mode is still being ended. I don't want the edit mode to end when the user does not want to save the row and I want the focus to stay on the current editing cell.

    The way I think this might  work is that if we can somehow stop the roweditended event chain in code, I tried to call e.Handled = true, but that doesn't do anything, the row is still being edit ended.
    A workaround I found is that If I move the confirmation dialog code to the rowvalidating event and set the IsValid to false to stop the row edit ended event being fired, however this causes an undesired side effect of the row turning to red, I have consulted with the business users, and they feel like it's too confusing to have the background turn red when there's no validation error.
    My question would be, how does telerik cancel the row level editing event without setting the IsValid to false?
  2. Boris
    Boris avatar
    276 posts

    Posted 17 Jul 2014 Link to this post

    Hello Gavin,

    A possible approach for fulfilling your requirement is to use the RowValidating and RowEditEnded events. In order to cancel the commit you can use the CancelEdit() method of the GridView.

    private void clubsGrid_RowValidating(object sender, GridViewRowValidatingEventArgs e)
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.No)

    As for returning to edit mode on the same row, you can check if the e.EditAction property is set to "Cancel" and use the BeginEdit() method of the GridViewRow.

    private void clubsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
                if (e.EditAction == Telerik.Windows.Controls.GridView.GridViewEditAction.Cancel)

    I hope this helps.

    Boris Penev
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top