Back to Devexpress

cxGridStoreAllDataViewStates Constant

vcl-cxgridcustomview-dfb5423c.md

latest8.3 KB
Original Source

cxGridStoreAllDataViewStates Constant

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

Declaration

delphi
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 | RestoreDataViewStateAllow you to store user interaction states in memory during the same session.StoreDataViewStateToStream | RestoreDataViewStateFromStreamAllow you to store only user interaction states in a separate stream.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.StoreToStream | RestoreFromStreamAllow 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:

delphi
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);
cpp
#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);

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.

delphi
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;
cpp
#include "System.SysUtils.hpp" // Declares the FileExists function
#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 "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
// ...

void __fastcall TMyForm::FormCreate(TObject *Sender)
{
  TFileStream *AFileStream;
  if(FileExists("GridConfig.dat"))
  {
    AFileStream = new TFileStream("GridConfig.dat", fmOpenReadWrite);
    try
    {
      // Restore the grid view layout structure along with selected records and the current focus position
      cxGrid1DBTableView1->RestoreFromStream(AFileStream, true, false,
        (TcxGridStorageOptions() << gsoUseFilter << gsoUseSummary) + cxGridStoreAllDataViewStates);
    }
    __finally
    {
      delete AFileStream;
    }
  }
}

void __fastcall TMyForm::FormDestroy(TObject *Sender)
{
  TFileStream *AFileStream = new TFileStream("GridConfig.dat", fmCreate | fmOpenReadWrite);
  try
  {
    // Save the grid view layout structure along with selected records and the current focus position
    cxGrid1DBTableView1->StoreToStream(AFileStream,
      (TcxGridStorageOptions() << gsoUseFilter << gsoUseSummary) + cxGridStoreAllDataViewStates);
  }
  __finally
  {
    delete AFileStream;
  }
}

See Also

cxTreeListStoreAllDataViewStates Global Constant

cxGridCustomView Unit