vcl-cxgridcustomview-dot-tcxcustomgridview-dot-restoredataviewstate-x28-cxgridcustomview-dot-tcxgridstorageoptions-x29.md
Restores user interaction states stored in memory after a StoreDataViewState procedure call.
procedure RestoreDataViewState(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, scroll position, etc.) during the same session.
Note
RestoreDataViewState procedure also clears all information saved using the StoreDataViewState procedure.RestoreDataViewState procedure call has no effect if no specified (AOptions) user interaction state is stored in memory (for example, if you did not call the StoreDataViewState or saved a different set of user interaction states).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/restore the focus position.gsoSelectedStores/restores selection.gsoTopRecordStores/restores the grid View scroll position.gsoExpandedStores/restores the expanded status for all records.gsoDetailStores/restores 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) between sessions in an INI file.StoreToRegistry | RestoreFromRegistryAllow you to store the grid View state (both data layout and user interaction states) between sessions in the system registry.StoreToStorage | RestoreFromStorageAllow you to store the grid View state between sessions in a custom storage.StoreDataViewStateToStream | RestoreDataViewStateFromStreamAllow you to store only user interaction states in a separate stream.
Footnotes
See Also