BaseView.RestoreLayoutFromXml(String) Method

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

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public void RestoreLayoutFromXml(
    string xmlFile
)
Public Sub RestoreLayoutFromXml(
    xmlFile As String
)

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.

Examples

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);
}

Implements

DevExpress.Utils.Serializing.ISupportXtraSerializer.RestoreLayoutFromXml(String)
See Also