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

Save and Restore Layout

  • 4 minutes to read

A pivot grid’s layout contains settings that determine the size and position of its visual elements. The layout can be saved and applied to any other WPF Pivot Grid control.

Base Concepts

DXPivotGrid Specifics

The DXPivotGrid provides the following options that specify which settings should be saved/restored:

Option Description
PivotSerializationOptions.AddNewFields Specifies whether the fields that exist in the pivot grid but not in a layout should be retained when it is restored.
PivotSerializationOptions.AddNewGroups Specifies whether the field groups that exist in the pivot grid but not in a layout should be retained when it is restored.
PivotSerializationOptions.RemoveOldFields Specifies whether fields that exist in the pivot grid but not in a layout should be discarded when it is restored.
PivotSerializationOptions.StoreLayoutMode Gets or sets which settings should be saved when saving the PivotGrid’s layout. This is an attached property.
<dxpg:PivotGridControl Name="pivotGridControl1" dxpg:PivotSerializationOptions.RemoveOldFields="False"/>

To manage the layout’s fields, use the PivotSerializationOptions.AddNewFields and PivotSerializationOptions.RemoveOldFields properties.

New fields are fields in the control, old fields are fields in the saved layout.

  • If old and new fields have the same ID, the control applies the saved layout changes to the fields in the control.

  • If old and new fields have the different ID, the behavior is as follows:

    • If both properties are true, the Pivot Grid removes the fields from the saved layout and keeps the fields in the control.

    • If both properties are false, the Pivot Grid restores the fields from the layout and removes the fields from the control.

    • If AddNewFields is true and RemoveOldFields is false, the Pivot Grid restores the fields from the layout and keeps the fields in the control.

    • If AddNewFields is false and RemoveOldFields is true, the Pivot Grid removes the fields from the layout and control.

To save all layout options (without appearance, data or client-side events settings), pass null (Nothing in Visual Basic) or the static PivotGridWebOptionsLayout.FullLayout property as the options parameter.

To save the layout, use the PivotGridControl.SaveLayoutToXml or PivotGridControl.SaveLayoutToStream method. To restore a saved layout, use the PivotGridControl.RestoreLayoutFromXml or PivotGridControl.RestoreLayoutFromStream method.

Important

The Pivot Grid uses a field’s Name to determine the field in a stored layout.

Example: How to Save and Load the DXPivotGrid’s Layout

The following example shows how to save the pivot grid’s layout to a file in XML format. To investigate how this works, click the “Save” button, which calls the PivotGridControl.SaveLayoutToXml method. Once saved, the pivot grid’s layout can then be restored by clicking the “Load” button, which calls the PivotGridControl.RestoreLayoutFromXml method.

Note

The complete sample project How to save and restore the layout to/from XML is available at GitHub.

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Imports HowToBindToMDB.NwindDataSetTableAdapters

Namespace HowToBindToMDB
    Partial Public Class MainWindow
        Inherits Window
        Private salesPersonDataTable As New NwindDataSet.SalesPersonDataTable()
        Private salesPersonDataAdapter As New SalesPersonTableAdapter()

        Public Sub New()
            InitializeComponent()
            pivotGridControl1.DataSource = salesPersonDataTable
        End Sub

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            salesPersonDataAdapter.Fill(salesPersonDataTable)
        End Sub

        Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            pivotGridControl1.SaveLayoutToXml("layout.xml")
        End Sub

        Private Sub buttonLoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            pivotGridControl1.RestoreLayoutFromXml("layout.xml")
        End Sub
    End Class
End Namespace