This is a migrated thread and some comments may be shown as answers.

how to cancel row level edit event

1 Answer 961 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 16 Jul 2014, 01:42 PM
Hi,
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?

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 17 Jul 2014, 04:10 PM
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)
            {
                this.clubsGrid.CancelEdit();
            }
        }

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)
            {
                e.Row.BeginEdit();
            }
        }

I hope this helps.

Regards,
Boris Penev
Telerik
 
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.
 
Tags
GridView
Asked by
Gavin
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or