BaseView.SaveLayoutToXml(String) Method

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

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll


public void SaveLayoutToXml(
    string xmlFile
Public Sub SaveLayoutToXml(
    xmlFile As String


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.


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.


The Document Manager identifies its child documents by names of controls hosted within these documents. Thus, its 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).


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


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) {
   // Restore the previously saved layout

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
   // Save the layout to an XML file


See Also