Skip to main content
A newer version of this page is available. .

BaseView.RestoreLayoutFromXml(String) Method

Restores a View’s layout from a specific XML file.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v19.2.dll

Declaration

public void RestoreLayoutFromXml(
    string xmlFile
)

Parameters

Name Type Description
xmlFile String

A string value specifying the path to the XML file from which View settings are read. If the specified file doesn’t exist, System.IO.FileNotFoundException type exception is raised.

Remarks

Use the RestoreLayoutFromXML method to load the View’s layout previously saved to an XML file with the help of the BaseView.SaveLayoutToXml method.

The ColumnView.OptionsLayout property controls which settings should be restored from the file.

Note

When restoring a layout during a form load (for instance, in your Form.Load event handler), you may need to call the GridControl.ForceInitialize method prior to the layout restoration. See this method to learn more.

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 snippets (auto-collected from DevExpress Examples) contain references to the RestoreLayoutFromXml(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