Back to Devexpress

Upgrading Layout

windowsforms-2383-common-features-save-and-restore-layouts-upgrading-layout.md

latest2.7 KB
Original Source

Upgrading Layout

  • Sep 10, 2023
  • 3 minutes to read

This topic describes issues that you may encounter while loading a layout from a data store in XtraGrid, XtraPivotGrid, XtraBars, XtraVerticalGrid, Tree List and XtraNavBar controls.

Controlling Layout Loading

Let’s consider the following situation. Assume that you have developed and deployed an application that uses a DevExpress .NET control (XtraGrid, XtraPivotGrid, XtraBars, etc.). The application allows an end-user to customize the layout and save it between application runs. The layout is automatically saved to an XML file when the application closes and loaded when the application starts. So the layout preferences of an end-user are stored in an XML file.

The application evolves and new features are implemented. For instance, new columns (in XtraGrid) and new groups (in XtraNavBar) are added as existing columns are removed, etc. When an end-user starts a new version of the application, the existing layout preferences are automatically loaded from the XML file, thus overriding the layout that was supplied with the new version of the application. As a result, new columns/groups, etc., can be hidden after the layout has been loaded.

To resolve this issue, controls provide two events.

  • LayoutUpgrade

  • BeforeLoadLayout

Layout Loading Specifics (Data Grid, Pivot Grid, TreeList, Vertical Grid)

WinForms Data Grid, Pivot Grid, TreeList, and Vertical Grid controls provide options that control how a layout is saved to/restored from a data store. These options are grouped within the OptionsLayout property. These include options that specify whether or not to save the control’s appearance and data-aware settings, visual options, etc. In addition, there are options that specify what to do with the columns/fields that exist in the layout being loaded, but not in the current control.

By default, the columns that exist in the current control, but not in the layout being loaded, are retained. Also, the columns that exist in the layout being loaded, but not in the current control’s layout, are destroyed.

To change this behavior use the OptionsColumnLayout.AddNewColumns and OptionsColumnLayout.RemoveOldColumns properties of the OptionsLayout object (for the TreeList control, use the AddNewColumns and RemoveOldColumns properties).

See Also

Save and Restore Layouts of DevExpress Controls