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

How to undo changes after RowEditEnded?

3 Answers 458 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 30 Nov 2010, 07:34 PM
I am handling the RowEditEnded event of my RadGridView to save the changes to the database through a service.  But if I get an error from the middle tier, I want to roll back those changes to the row.

At the time RowEditEnded is raised, it is too late to call CancelEdit(), so I thought that using the OldValues property of  GridViewRowEditEndedEventArgs would be the best way to go, and apply them to each cell in the row. The problem is that OldValues is a dictionary and GridViewCellBase can only be indexed by position.  I could find each cell binding and find the item in OldValues that matches it, but it seems to me that there should be a better way.

Is there an easy way to do this?

3 Answers, 1 is accepted

Sort by
0
Roger
Top achievements
Rank 1
answered on 30 Nov 2010, 07:53 PM
btw, I also tried this, but the cell value doesn't visually change.

foreach (var oldValue in e.OldValues)
{
    var cell = e.Row.GetCellFromPropertyName(oldValue.Key);
    if (cell == null)
        continue;
 
    cell.Value = oldValue.Value;
}
0
Accepted
Veselin Vasilev
Telerik team
answered on 01 Dec 2010, 11:04 AM
Hi Roger,

Please find attached a sample project. Edit a row and then click on the Undo Changes button.

Hope this will get you started.

Best wishes,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Roger
Top achievements
Rank 1
answered on 01 Dec 2010, 06:07 PM
Perfect!
Tags
GridView
Asked by
Roger
Top achievements
Rank 1
Answers by
Roger
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or