Skip to main content

BaseView.SaveLayoutToXml(String) Method

Saves a View’s layout to a specific XML file.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

public void SaveLayoutToXml(
    string xmlFile
)

Parameters

Name Type Description
xmlFile String

A string value specifying the path to the file where a View layout should be stored. If an empty string is specified, an exception is raised.

Remarks

Use the SaveLayoutToXML method to save a View’s layout to a specific XML file at runtime. You can then restore saved settings using the BaseView.RestoreLayoutFromXml method.

The ColumnView.OptionsLayout property controls which settings should be saved to the file.

Important

The Document Manager identifies its child documents by names of controls hosted within these documents. Thus, it is recommended that you set unique names for these controls. Failure to comply with this recommendation will result in an exception for certain scenarios (e.g., saving and restoring a View layout by using the SaveLayoutToXml method).

Tip

You can utilize the Persistence Behavior or Workspace Manager component to save and restore layouts for all supported DevExpress controls at once.

Example

This example shows how to save and restore the layout of the GridControl.MainView between application runs. The form’s Load event is handled to restore the layout previously saved to an XML file. The form’s Closing event is handled to save the current layout to the specified file.

Note that the GridControl.ForceInitialize method is called before the layout is restored in the Form.Load event. This method needs to be called before a grid’s settings are changed in the Form.Load event. It finishes the control’s initialization and thus ensures that all the changes that will be made do not conflict with the options that have been customized at design time.

using DevExpress.XtraGrid;
// ...
string fileName = "c:\\XtraGrid_SaveLayoutToXML.xml";

private void Form1_Load(object sender, System.EventArgs e) {
   gridControl1.ForceInitialize();
   // Restore the previously saved layout
   gridControl1.MainView.RestoreLayoutFromXml(fileName);
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
   // Save the layout to an XML file
   gridControl1.MainView.SaveLayoutToXml(fileName);
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SaveLayoutToXml(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also