Skip to main content
All docs
V25.1

cxGridStoreAllDataViewStates Constant

Specifies a set of flags that correspond to all user interaction states in a grid View.

Declaration

const cxGridStoreAllDataViewStates = [gsoUseDataViewState, gsoExpanded, gsoFocusedRecord, gsoFocusedItem, gsoSelected, gsoTopRecord, gsoFocusedView, gsoDetail];

Remarks

Pass the cxGridStoreAllDataViewStates constant as the corresponding parameter in all Store~/Restore~ methods declared in the TcxCustomGridView class if you need to store/restore all supported interaction states:

StoreDataViewState | RestoreDataViewState
Allow you to store user interaction states in memory during the same session.
StoreDataViewStateToStream | RestoreDataViewStateFromStream
Allow you to store only user interaction states in a separate stream.
StoreToIniFile | RestoreFromIniFile
Allow you to store the grid View state (both data layout and user interaction states) in an INI file.
StoreToRegistry | RestoreFromRegistry
Allow you to store the grid View state (both data layout and user interaction states) in the system registry.
StoreToStream | RestoreFromStream
Allow you to store the grid View state (both data layout and user interaction states) in a stream.

Code Examples

Restore User Interaction States After Data Updates

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);

Store Grid View State Between Sessions

The code example in this section demonstrates form OnDestroy and OnCreate event handlers. These handlers call StoreToStream and RestoreFromStream procedures to save and restore user interaction states (selection, focus, scroll position, etc.) in addition to the filter state and summaries.

uses
  System.SysUtils,  // Declares the FileExists function
  cxGrid,  // Declares the TcxGrid control
  cxGridCustomView,  // Declares the TcxCustomGridView class and related types
  cxGridDBTableView;  // Declares the TcxGridDBTableView class
// ...

procedure TMyForm.FormCreate(Sender: TObject);
var
  AFileStream: TFileStream;
begin
  if FileExists('GridConfig.dat') then
  begin
    AFileStream := TFileStream.Create('GridConfig.dat', fmOpenReadWrite);
    try
      // Restore the grid view layout structure along with selected records and the current focus position
      cxGrid1DBTableView1.RestoreFromStream(AFileStream, True, False,
       [gsoUseFilter, gsoUseSummary] + cxGridStoreAllDataViewStates)
    finally
      AFileStream.Free;
    end;
  end;
end;

procedure TMyForm.FormDestroy(Sender: TObject);
var
  AFileStream: TFileStream;
begin
  AFileStream := TFileStream.Create('GridConfig.dat', fmCreate or fmOpenReadWrite);
  try
   // Save the grid view layout structure along with selected records and the current focus position
   cxGrid1DBTableView1.StoreToStream(AFileStream,
     [gsoUseFilter, gsoUseSummary] + cxGridStoreAllDataViewStates)
  finally
    AFileStream.Free;
  end;
end;
See Also