Skip to main content

PivotGridControl.RestoreLayoutFromXml(String) Method

SECURITY NOTE

Deserializing layout settings from untrusted resources may create security issues. Review the following help topic for additional information: Safe Deserialization.

Restores the pivot grid’s layout from the specified XML file.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v24.2.dll

NuGet Package: DevExpress.Wpf.PivotGrid

Declaration

public void RestoreLayoutFromXml(
    string fileName
)

Parameters

Name Type Description
fileName String

A String value that specifies the target file name.

Remarks

To save the pivot grid’s layout, use the PivotGridControl.SaveLayoutToXml method.

Note that you should specify unique names for all pivot grid fields to correctly save and restore the layout. You can do this using the PivotGridField.Name property.

To learn more, see Save and Restore Layout.

Example

The following example shows how to save the Pivot Grid’s layout to a file in XML format. The “Save” button calls the PivotGridControl.SaveLayoutToXml method. The “Load” button calls the PivotGridControl.RestoreLayoutFromXml method to restore the saved layout.

using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;

namespace HowToBindToMDB {
    public partial class MainWindow : Window {
        NwindDataSet.SalesPersonDataTable salesPersonDataTable = new NwindDataSet.SalesPersonDataTable();
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = salesPersonDataTable;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            salesPersonDataAdapter.Fill(salesPersonDataTable);
        }
        private void buttonSave_Click(object sender, RoutedEventArgs e) {
            pivotGridControl1.SaveLayoutToXml("layout.xml");
        }
        private void buttonLoad_Click(object sender, RoutedEventArgs e) {
            pivotGridControl1.RestoreLayoutFromXml("layout.xml");
        }
    }
}
<Window x:Class="HowToBindToMDB.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        Title="MainWindow" Height="350" Width="525"  Loaded="Window_Loaded">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <dxpg:PivotGridControl Name="pivotGridControl1" DataProcessingEngine="Optimized">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCategory" Caption="Category" Area="RowArea">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="CategoryName"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldYear" Area="ColumnArea" Caption="Year">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="OrderDate" GroupInterval="DateYear"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldExtendedPrice" Area="DataArea" CellFormat="c0">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Extended Price"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Name="buttonSave" Content="Save" Padding="8, 4, 8, 4" 
                    Margin="4" Click="buttonSave_Click" />
            <Button Name="buttonLoad" Content="Load" Padding="8, 4, 8, 4" 
                    Margin="4" Click="buttonLoad_Click" />
        </StackPanel>
    </Grid>
</Window>
See Also