Save and Restore Layout
- 2 minutes to read
A pivot grid's layout contains settings which determine how its visual elements behave - their size, position within the control, etc. A layout can be saved and then applied to any other PivotGridControl. This allows you to customize a pivot grid just once, and then apply the saved settings to other pivot grids in other applications.
#Concepts
The DXPivotGrid provides multiple options, allowing you to specify which settings should be saved/restored. These options are described below:
Option | Description |
---|---|
Pivot |
Specifies whether the fields that currently exist in the pivot grid, but do not exist in a layout when it's restored, should be retained. |
Pivot |
Specifies whether the field groups that currently exist in the pivot grid, but do not exist in a layout when it's restored, should be retained. |
Pivot |
Specifies whether fields that exist in a layout when it is restored, but don't currently exist in the pivot grid, should be discarded. |
Pivot |
Gets or sets which settings should be saved when saving the Pivot |
<dxpg:PivotGridControl Name="pivotGridControl1" dxpg:PivotSerializationOptions.RemoveOldFields="False"/>
To save the layout, use the PivotGridControl.SaveLayoutToStream or PivotGridControl.SaveLayoutToXml method. To restore the previously saved layout, use the PivotGridControl.RestoreLayoutFromStream or PivotGridControl.RestoreLayoutFromXml method respectively.
NOTE
The Pivot
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.
#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.SaveLayoutToStream method. Once saved, the pivot grid's layout can then be restored by clicking the "Load" button, which calls the PivotGridControl.RestoreLayoutFromStream method.