Skip to main content

How to Undo/Redo Layout Changes Made at Runtime

  • 2 minutes to read

This topic describes how end-users can undo/redo changes made to the layout and how you can accomplish this in code.

In customization mode, any changes made by end-users to a layout are tracked by the Undo/Redo Manager. Each change causes the Undo/Redo Manager to save the current layout state into an in-memory Undo/Redo list and advance the current position in the list. The Undo/Redo Manager allows users to traverse the list backwards and forwards and apply the stored state to the layout control, thus undoing/redoing changes. An Undo operation moves the current position in the list backwards, while the Redo operation moves it forwards. To keep the list synchronized with the current state, the Undo/Redo Manager always saves the layout state at the current position in the list and clears all its subsequent entries.

In code, you can perform undo/redo operations using members of the Undo/Redo Manager accessible via the layout control’s UndoRedoManager property.

The following code snippet demonstrates how to undo all changes made at runtime:

while layoutControl.UndoRedoManager.CanUndo do
  layoutControl.UndoRedoManager.Undo();

End-users can sequentially undo all changes they made to the layout and apply them again via the Customization Form

or customization context menus

Changes made to a layout group’s expanded state are not tracked and so cannot be reverted in this manner.

In addition, in customization mode, end-users can click the Store Layout button to store the layout in memory and external data stores. Later, end-users can click the Restore Layout button to restore the layout and undo any changes that have been subsequently introduced.

Restoring the layout in this manner is considered a normal change to the layout, so it’s added to the Undo/Redo list and can be undone or reapplied as described above.

See Also