[Expand]General Information
[Collapse]WinForms Controls
 [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
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Tooltip Management
  [Collapse]Saving and Restoring Layouts
    How to: Save Layout to a Stream
    Saving and Restoring Layout Basics
    How to: Save Layout to the System Registry
    Layout Options (XtraGrid, XtraPivotGrid)
    How to: Save Layout to 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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Saving and Restoring Layout Basics

This document provides general information on the saving and restoring of layouts of DevExpress .NET controls (XtraGrid, XtraPivotGrid, XtraTreeList, XtraVerticalGrid, XtraBars, XtraScheduler, Layout Control).

Expanded Saving and Restoring Layout Basics

Specific DevExpress .NET controls and components allow you to save information on their layouts to a data store (XML file, stream and system registry) and then restore it. This information may include the visibility, position and size of visual elements, their appearance settings, filter, sorting, grouping and summary information, etc. Particular controls do not support saving specific settings (e.g. appearance settings) when their layouts are saved. Other controls introduce options to control which settings need to be saved/restored when the layout is saved/restored.

The controls that allow you save their layouts generally provide the following methods: SaveLayoutToRegistry, SaveLayoutToStream and SaveLayoutToXml. Note that it is not possible to save multiple layouts to a single data store. Each of the layouts must be stored in a separate data store.

To restore a layout, one of the corresponding methods can be used: RestoreLayoutFromRegistry, RestoreLayoutFromStream or RestoreLayoutFromXml.

For instance, in Grid Control you can use the BaseView.SaveLayoutToXml and BaseView.RestoreLayoutFromXml methods to save the layout of a Grid Control's View to an XML file, and then restore it.

When saving a layout to the registry, you can define an absolute or relative registry key as the parameter. For instance, specifying "Software\MyCompany\MyProject\" as a partial key will result in saving the settings to the "HKEY_CURRENT_USER\Software\MyCompany\MyProject\" path. You can also specify the entire key if you need to store the layout to another root key.

In Grid Control and PivotGrid controls, it is possible to specify which options need to be saved/restored when a layout is saved/restored. By default, when a control's layout is saved to a data store, a specific set of properties is saved. These include the visibility state, position and size of the columns/fields, sorting, grouping and summary information, all the settings that determine the visibility of various visual elements, etc. However, the appearance and certain other settings are not saved. To customize which options need to be saved/restored, you can use specific overloads of the SaveLayoutTo... and RestoreLayoutFrom... methods or the OptionsLayout property provided by the controls. See the Layout Options (XtraGrid, XtraPivotGrid) topic for more information.

To prevent a layout from being restored from a data store and applied to a control, you can handle a control's BeforeLoadLayout event.

Expanded When to Call the "SaveLayoutTo..." and "RestoreLayoutFrom..." Methods

Typically, the RestoreLayoutFrom... methods must be called when a Form/UserControl is being loaded. You can handle the Form.Load/UserControl.Load events to do this.

The SaveLayoutTo... methods should be called when the Form/UserControl are closed or destroyed. When DevExpress controls are positioned within a Form, use the Form.FormClosing event to save the layout of the controls. When the controls are positioned within a UserControl, save the layout of the controls via the overridden UserControl.Dispose method.

Expanded Post-Restore Customization

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

The OptionsLayout.LayoutVersion property allows you to explicitly label different layout versions. The LayoutUpgrage event raises only when the loaded layout version differs from the currently active one.

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