Skip to main content

Local Data Stores

  • 3 minutes to read

Sometimes end-users need to work with PivotGridControl when no connection to the database exists. Whenever a connection to the database exists, an end-user can save the Pivot Grid Control’s data to a file or stream. Then, when the connection isn’t available, it is possible to load the saved data and continue working with the PivotGridControl.

Creating and Using Local Data Stores

The PivotGridControl.SavePivotGridToFile method saves Pivot Grid Control’s current data to a file for later use (if required, you can save the data to a stream via the PivotGridControl.SavePivotGridToStream method). These methods save all the original data from the data store, together with the full layout, including appearance settings. It is possible to set the method’s compress parameter to true to enable data compression. This will reduce the size of the resultant file, but may increase the time required for data saving/loading.

To load the saved data, a PivotFileDataSource object must be created and assigned to the PivotGridControl.DataSource property. This automatically restores the layout portion from the specified file and loads the saved data. After data has been restored, an end-user is able to manipulate the Pivot Grid Control’s layout, sort and filter data, etc.

Note

A PivotFileDataSource object can be created using the constructor that takes a Stream object as a parameter. In this instance, do not dispose of the specified stream until the PivotFileDataSource object is assigned to the PivotGridControl.DataSource property.

Note

Typically, you save and restore data in the same control. However, it is possible to restore the saved data in another PivotGridControl. In this instance, custom logic implemented in the first Pivot Grid Control in code will not be available in the second control. For example, unbound fields that are populated via the PivotGridControl.CustomUnboundFieldData event will not provide any data in the second PivotGridControl.

Example

The following example shows how to save the Pivot Grid Control’s data to a file, and then load it later.

To save the data the PivotGridControl.SavePivotGridToFile method is called. To restore the data, a PivotFileDataSource object is initialized and assigned to the PivotGridControl.DataSource property.

using DevExpress.Data.PivotGrid;

string filePath = "c:\\pivotData.dat";
// Save the control's data to the file.
pivotGridControl1.SavePivotGridToFile(filePath);

//...

// Restore the saved data
PivotFileDataSource ds = new PivotFileDataSource(filePath);
pivotGridControl1.DataSource = ds;