Skip to main content
A newer version of this page is available.
All docs
V17.2

Saving and Restoring Layout Basics

  • 3 minutes to read

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

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.

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.