Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
415
Undo All?
posted

I have successfully used the UndoManager framework before in a PivotGrid which I thought would be very difficult. So, I am pretty familiar with the UndoManager already. However, I am having trouble undoing all.  I cannot use transactions to log these changes so I am just relying on the following loop to do this for me:

UndoMgr.Suspend();

while (UndoMgr.CanUndo)

{
   //UndoMgr.PreventMerge();
   UndoMgr.Undo();
}
UndoMgr.ClearHistory();
UndoMgr.Resume();

I tried this both with the suspend call at the beginning and without. The PreventMerge() sounded promising but also didn't work. If I have Suspend in there, I get an System.InvalidOperationException. I guess I can't Undo while suspended. If I take out the call to Suspend, then each Undo operation is logged as an undoable transaction and I get double the number of undos that I want and I end up right back where I was with the undos having no effect.

What I really want is a function UndoManager.UndoAll() that just undoes everything on the Undo list and nothing more. Is that possible? It seems like I've seen samples where you can undo N operations at once (not using transactions). Is there a way to undo all on the list and the just clear the history in a clean way.

Thanks!