Local Data Stores
- 2 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 using 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 resulting file, but may increase the time required for data saving/loading.
To load 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.
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.
Typically, you save and restore data in the same control. However, it is possible to restore 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 using the PivotGridControl.CustomUnboundFieldData event will not provide any data in the second PivotGridControl.