PivotGridControl.LoadCollapsedStateFromStream(Stream) Method

Restores the collapsed state of field values from the specified stream.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v21.2.dll


public void LoadCollapsedStateFromStream(
    Stream stream


Name Type Description
stream Stream

A Stream descendant from which the collapsed state of field values is read. If null (Nothing in Visual Basic), an exception is raised.


Use the LoadCollapsedStateFromStream method to load the collapsed state of field values that has been written to a stream via the PivotGridControl.SaveCollapsedStateToStream method.

The collapsed states of field values can only be restored in the same layout they were saved in. If the control layout was changed after saving the collapsed states (for instance, some fields have been reordered or hidden), the LoadCollapsedStateFromStream method may have no effect, or may restore the collapsed states incorrectly. To ensure that the collapsed states are loaded correctly, prevent end-users from changing the control layout (use the PivotGridOptionsCustomization.AllowDrag and PivotGridOptionsCustomization.AllowHideFields properties), or save and load the field values’ collapsed states together with the control layout (use the PivotGridControl.SaveLayoutToStream and PivotGridControl.RestoreLayoutFromStream methods).


The LoadCollapsedStateFromStream method has no effect if used when data is not loaded (i.e. the PivotGridControl.DataSource property is not initialized).


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.


Field values' collapsed states can be restored only in the same layout they have been saved in. This example shows how to save and load a control's layout together with collapsed states to ensure that the states are loaded in the appropriate layout.This example displays a pivot grid control and three buttons: Save, Load and Clear. When the Save button is clicked, the control layout and field values' collapsed states are saved to streams via the SaveLayoutToStream and SaveCollapsedStateToStream methods, respectively. On the Load button click, the RestoreLayoutFromStream method is firstly called to restore the layout, and then the collapsed states are loaded using the LoadCollapsedStateFromStream method. This ensures that even if you remove all fields from the pivot grid via the Clear button, the control's state will be restored when you click the Load button.

View Example

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

namespace XtraPivotGrid_SaveLoadCollapsedState {
    public partial class Form1 : Form {
        MemoryStream layoutStream = new MemoryStream();
        MemoryStream collapseStateStream = new MemoryStream();
        public Form1() {
        private void Form1_Load(object sender, EventArgs e) {
            nwindDataSetTableAdapters.ProductReportsTableAdapter adapter =
                new nwindDataSetTableAdapters.ProductReportsTableAdapter();
            pivotGridControl1.DataSource = adapter.GetData();
        private void btnSave_Click(object sender, EventArgs e) {
            layoutStream = new MemoryStream();
            pivotGridControl1.SaveLayoutToStream(layoutStream, OptionsLayoutBase.FullLayout);
            collapseStateStream = new MemoryStream();
        private void btnLoad_Click(object sender, EventArgs e) {
            layoutStream.Seek(0, SeekOrigin.Begin);
            pivotGridControl1.RestoreLayoutFromStream(layoutStream, OptionsLayoutBase.FullLayout);
            collapseStateStream.Seek(0, SeekOrigin.Begin);
        private void btnClear_Click(object sender, EventArgs e) {
See Also