[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Expand]Application Appearance and Skin Colors
  [Expand]Filtering UI Context
   Find Panel Syntax
  [Expand]Graphics Performance and High DPI
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML-inspired Text Formatting
  [Collapse]Save and Restore Layouts
    How to: Save a control's layout to a stream
    How to: Save a control's layout to the system registry
    Layout Options (XtraGrid, XtraPivotGrid)
    How to: Save a control's layout to a XML file
    Upgrading Layout
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Save and Restore Layouts

DevExpress controls allow you to save their layout information to data stores (XML file, stream and system registry) and then restore it. Different controls save different sets of options. Typically, the saved layout includes the visibility, position, and size of visual elements, their sort, group, summary, and filter settings.

You can customize which properties need to be saved/restored and perform actions on layout loading.

Two dedicated DevExpress components allow you to save/restore the layout of all DevExpress controls within a form along with that form's bounds and state. See the following sections for more information.

Expanded Save & restore the form's bounds and state and all child controls' layouts

You can use the following components to save/restore a form's bounds/state along with the layouts of all DevExpress controls that reside within this form.

  • Persistence Behavior (part of the Behavior Feature) - Automatically saves the layout information to a file or the system registry when the Form.FormClosed event fires and restores the saved layout when the Form.Load event fires.
  • Workspace Manager - Allows you to manually save the layout information to a file, stream or system registry. Supports multiple layouts (workspaces) and animation effects.

Expanded Save & restore the layouts of individual controls

DevExpress controls and components contain methods used to save/restore their layouts to/from a file/stream/system registry.

  • SaveLayoutToRegistry, SaveLayoutToStream and SaveLayoutToXml
  • RestoreLayoutFromRegistry, RestoreLayoutFromStream or RestoreLayoutFromXml

You cannot save multiple layouts to a single data store when using these methods.

When you save a layout to the system registry, you can define an absolute or relative registry key as a destination. For instance, when you specify the "Software\MyCompany\MyProject" destination, the actual path will be the "HKEY_CURRENT_USER\Software\MyCompany\MyProject" path.

Expanded When to call the "SaveLayoutTo..." and "RestoreLayoutFrom..." methods

You can handle the Form.Load/UserControl.Load events to restore control layouts.

To save layouts of controls positioned within a form, handle the Form.FormClosing event. For controls residing within a UserControl, override the UserControl.Dispose method.

Expanded Layout options

DevExpress controls provide settings to customize the layout save/restore operations. These settings allow you to specify:

  • which properties are saved/restored;
  • whether or not new items are retained after you load an old layout;
  • whether or not to discard the items that do not exist in the control, but exist in the loaded layout;
  • the layout version.

The list below shows the objects used to access these layout-specific settings.

For information on the options available in the Data Grid and Pivot Grid controls, see Layout Options (XtraGrid, XtraPivotGrid).

The layout-specific settings the DevExpress controls expose affect all save/restore operations (when you use Persistence Behavior, Workspace Manager or call control.SaveLayoutTo... and control.RestoreLayoutFrom... default overloads).

The controls' SaveLayoutTo... and RestoreLayoutFrom... methods have overloads with and without the options parameter. For instance, the overloads of the BaseView.SaveLayoutToXml and BaseView.RestoreLayoutFromXml methods are declared as follows.

The default overloads (without the options parameter) take into account the layout-specific settings exposed by the control. The overloads that have the options parameter take into account the specified settings and ignore the layout-specific settings exposed by the control.

Expanded Post-restore customization

After a layout is restored, you can perform additional customization in a control's LayoutUpgrade event handler. In the "Customize layout during restoration" demo, a Data Grid's BaseView.LayoutUpgrade event is handled to hide the first column.

A control's OptionsLayout.LayoutVersion property allows you to explicitly label different layout versions. The LayoutUpgrage event is raised only when the loaded layout version differs from the currently active one.

See Upgrading Layout for more information.

Expanded Cancel layout restore operations

You can handle a control's BeforeLoadLayout event to prevent a layout from being loaded in certain cases. For instance, you can cancel the restore operation if the loaded layout's version does not match the control's LayoutVersion.

Expanded See Also

Is this topic helpful?​​​​​​​