Skip to main content

PivotGridControl.SaveCollapsedStateToFile(String) Method

Saves the collapsed state of field values to the specified file.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v24.1.dll

NuGet Package: DevExpress.Win.PivotGrid

Declaration

public void SaveCollapsedStateToFile(
    string path
)

Parameters

Name Type Description
path String

A String value which specifies the path to the file to which the collapsed state of field values is saved. If the specified file doesn’t exist, it is created.

Remarks

The saved settings can then be restored using the PivotGridControl.LoadCollapsedStateFromFile method.

Note

The collapsed states for server mode and regular data sources are stored in different formats and not compatible with each other. Some issues can appear on restoring the collapsed state from different data source modes.

Example

This example demonstrates how to restore the Pivot Grid layout and row/column state.

Save and restore layout

View Example

The Save button uses the PivotGridControl.SaveLayoutToStream and PivotGridControl.SaveCollapsedStateToStream methods to save the layout and field values’ collapsed state to memory streams.

The Load button uses the PivotGridControl.RestoreLayoutFromStream and PivotGridControl.LoadCollapsedStateFromStream methods to restore the saved layout and column/row state.

The Clear button clears the field collection.

using System;
using System.IO;
using System.Windows.Forms;
using DevExpress.Utils;

namespace XtraPivotGrid_RestoreLayoutExample {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        MemoryStream layoutStream = new MemoryStream();
        MemoryStream collapseStateStream = new MemoryStream();
        public Form1() {
            InitializeComponent();
            btnClear.Enabled = false;
        }
        private void Form1_Load(object sender, EventArgs e) {
            excelDataSource1.FileName = "SalesPerson.xlsx";
            excelDataSource1.Fill();
            pivotGridControl1.DataSource = excelDataSource1;
        }
        private void btnSave_Click(object sender, EventArgs e) {
            if (pivotGridControl1.Fields.Count > 0) {
                layoutStream.Dispose();
                layoutStream = new MemoryStream();
                pivotGridControl1.SaveLayoutToStream(layoutStream, OptionsLayoutBase.FullLayout);
                collapseStateStream.Dispose();
                collapseStateStream = new MemoryStream();
                pivotGridControl1.SaveCollapsedStateToStream(collapseStateStream);
                btnClear.Enabled = true;
            }
        }
        private void btnLoad_Click(object sender, EventArgs e) {
            if (layoutStream.Length > 0 && collapseStateStream.Length > 0) {
                layoutStream.Seek(0, SeekOrigin.Begin);
                pivotGridControl1.RestoreLayoutFromStream(layoutStream, OptionsLayoutBase.FullLayout);
                collapseStateStream.Seek(0, SeekOrigin.Begin);
                pivotGridControl1.LoadCollapsedStateFromStream(collapseStateStream);
            }
        }
        private void btnClear_Click(object sender, EventArgs e) {
            if (layoutStream.Length > 0 && collapseStateStream.Length > 0) {
                pivotGridControl1.Fields.Clear();
            }
        }
    }
}
See Also