Failed DataPortal Update doesn't Undo properly in a grid?

Failed DataPortal Update doesn't Undo properly in a grid?

Old forum URL: forums.lhotka.net/forums/t/3305.aspx


lotrij posted on Tuesday, July 31, 2007

Hey,

I have an EditableRootListBase bound to an Infragistics UltraGrid.  If I try to update an object and that update results in an exception being thrown in the DataPortal_Update method, the undo state of the object is lost and the end user can't cancel their edit.  The original state of the object is lost (popped off of the undo stack) so the end user can't undo the edit (from their perspective at least, no data is actually modified).

I put some break points around and here's what I saw:
*Right before the end user clicks off the row to confirm their edit, the underlying object has an edit level of 1.
*When the end user clicks off of the row, IEditableObject.EndEdit is called.  This results in ApplyEdit being called which results in  AcceptChanges being called.
*AcceptChanges pops a layer off of the undo stack, bringing the object's edit level/undo count to 0, and throwing away the object's original state.
*AcceptChangesComplete is then called, which ultimately leads to EditableRootListBase's SaveItem to be called.
*At this point the object's edit level is still 0, and Save is called on it.  This leads to DataPortal_Update being called which throws an exception.
*Somehow/somewhere along the way the grid knows that an error has occured, so it doesn't switch rows.  It pops up a message box with the exception information.
*An IEditableObject.BeginEdit isn't called on the row right away, so I can click off of it without another EndEdit attempt.  This is probably the grid's fault.  If I try to edit the row (by clicking on a cell), a IEditableObject.BeginEdit will be called, and an attempt to click off of the row causes the expected error message to pop up without a row change.
*If, while still in edit mode on the row, I try to hit escape to cancel the edit, the new state still shows since the old state has been lost.

Should the pop of state happen before the save?  It makes it so that the original state is lost before even knowing whether or not the update will succeed.

RockfordLhotka replied on Tuesday, July 31, 2007

This is under discussion in another thread:

http://forums.lhotka.net/forums/thread/16450.aspx

Copyright (c) Marimer LLC