Back to Devexpress

TcxGridStorageOptions Type

vcl-cxgridcustomview-48152f2c.md

latest12.4 KB
Original Source

TcxGridStorageOptions Type

A set of flags that correspond to individual grid View settings and user interaction information stored in a file, stream, or system registry.

Declaration

delphi
TcxGridStorageOptions = set of TcxGridStorageOption;

Referenced Class

TypeDescription
TcxGridStorageOption

A flag that corresponds to an individual grid View information storage option.

|

Remarks

A TcxGridStorageOptions value can include any TcxGridStorageOption flag to indicate required grid View settings and user interaction states.

You need to use gsoUseDataViewState together with all required flags when you call the following methods to store/restore corresponding user interaction states in addition to the data layout:

Tip

You can use only the cxGridStoreAllDataViewStates constant if you need to store all user interaction states (as demonstrated in the Code Examples section below).

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

Direct TcxGridStorageOptions Type References

View Information Store Procedures

The following information store procedures accept a TcxGridStorageOptions value:

TcxCustomGridView.StoreDataViewStateStores specified user interaction states in memory.TcxCustomGridView.StoreDataViewStateToStreamSaves specified user grid View interaction states to a stream.TcxCustomGridView.StoreToIniFileSaves grid View state information to an INI file.TcxCustomGridView.StoreToRegistrySaves specified View data structure and user interaction information to the system registry.TcxCustomGridView.StoreToStorageSaves grid View data layout and user interaction states to a file in a custom data format.TcxCustomGridView.StoreToStreamSaves specified View data structure and user interaction information to a stream.

View Information Restore Procedures

The following information restore procedures accept a TcxGridStorageOptions value:

TcxCustomGridView.RestoreDataViewStateRestores user interaction states stored in memory after a StoreDataViewState procedure call.TcxCustomGridView.RestoreDataViewStateFromStreamRestores the previously saved data view state from a stream.TcxCustomGridView.RestoreFromIniFileRestores previously saved grid View state information from an INI file.TcxCustomGridView.RestoreFromRegistryRestores previously saved grid View state information from the system registry.TcxCustomGridView.RestoreFromStorageRestores previously saved grid View state information from a file in a custom data format.TcxCustomGridView.RestoreFromStreamRestores previously saved grid View state information from a stream. See Also

TcxTreeListStorageOptions Type

cxGridCustomView Unit