vcl-cxgridcustomview-dot-tcxcustomgridview-dot-storedataviewstate-x28-cxgridcustomview-dot-tcxgridstorageoptions-x29.md
Stores specified user interaction states in memory.
procedure StoreDataViewState(AOptions: TcxGridStorageOptions);
| Name | Type | Description |
|---|---|---|
| AOptions | TcxGridStorageOptions |
Specifies a set of individual user interaction states stored in memory.
|
Call StoreDataViewState and RestoreDataViewState procedures to save and restore specified user interaction states (selection, focus, the scroll position, etc.) during the same session.
Note
A RestoreDataViewState call clears all user interaction states saved using the StoreDataViewState procedure.
If you need to store user interaction states in a separate stream, call StoreDataViewStateToStream and RestoreDataViewStateFromStream procedures.
Pass a set of all required flags[1] as the AOptions parameter to store/restore corresponding grid View states:
gsoFocusedItem | gsoFocusedRecord | gsoFocusedViewStore the focus position.gsoSelectedStores selection.gsoTopRecordStores the grid View scroll position.gsoExpandedStores the expanded status for all records.gsoDetailStores the active detail grid View. Applicable only to master-detail grid View relationships.
Note
gsoUseFilter, gsoUseSummary, and gsoUseDataViewState flags have no effect on StoreDataViewState/RestoreDataViewState and StoreDataViewStateToStream/RestoreDataViewStateFromStream procedure calls.
Use these flags in StoreToIniFile/RestoreFromIniFile, StoreToRegistry/RestoreFromRegistry, StoreToStorage/RestoreFromStorage, StoreToStream/RestoreFromStream calls instead.
The following code example restores selection, focus, and the scroll position after a refresh operation in the bound dataset:
uses
FireDAC.Comp.Client, // Declares the TFDQuery component
cxGrid, // Declares the TcxGrid control
cxGridCustomView, // Declares the TcxCustomGridView class and related types
cxGridDBTableView; // Declares the TcxGridDBTableView class
// ...
cxGrid1DBTableView1.StoreDataViewState(cxGridStoreAllDataViewStates);
FDQuery1.Refresh;
cxGrid1DBTableView1.RestoreDataViewState(cxGridStoreAllDataViewStates);
#include "FireDAC.Comp.Client.hpp" // Declares the TFDQuery component
#include "cxGrid.hpp" // Declares the TcxGrid control
#include "cxGridCustomView.hpp" // Declares the TcxCustomGridView class and related types
#include "cxGridDBTableView.hpp" // Declares the TcxGridDBTableView class
// Add the following linker directives to the corresponding CPP source file:
#pragma link "FireDAC.Comp.Client" // Required to use FireDAC.Comp.Client.hpp declarations
#pragma link "cxGrid" // Required to use cxGrid.hpp declarations
#pragma link "cxGridCustomView" // Required to use cxGridCustomView.hpp declarations
#pragma link "cxGridDBTableView" // Required to use cxGridDBTableView.hpp declarations
// ...
cxGrid1DBTableView1->StoreDataViewState(cxGridStoreAllDataViewStates);
FDQuery1->Refresh();
cxGrid1DBTableView1->RestoreDataViewState(cxGridStoreAllDataViewStates);
Alternatively, you can store grid View data layout and user interaction states in a stream, INI file, system registry, or custom storage. The TcxCustomGridView class implements the following Store~/Restore~ method pairs in addition to StoreDataViewState and RestoreDataViewState:
StoreToIniFile | RestoreFromIniFileAllow you to store the grid View state (both data layout and user interaction states) in an INI file.StoreToRegistry | RestoreFromRegistryAllow you to store the grid View state (both data layout and user interaction states) in the system registry.StoreToStorage | RestoreFromStorageAllow you to store the grid View state (both data layout and user interaction states) in a custom data format.StoreDataViewStateToStream | RestoreDataViewStateFromStreamAllow you to store only user interaction states in a separate stream.
Footnotes
See Also