Back to Devexpress

cxTreeListStoreAllDataViewStates Constant

vcl-cxtl-0238c8a8.md

latest6.4 KB
Original Source

cxTreeListStoreAllDataViewStates Constant

Specifies a set of flags that correspond to all user interaction states in a Tree List control.

Declaration

delphi
const cxTreeListStoreAllDataViewStates = [tsoUseDataViewState, tsoExpanded, tsoFocusedRecord, tsoFocusedItem, tsoSelected, tsoTopRecord];

Remarks

Pass the cxTreeListStoreAllDataViewStates constant as the corresponding parameter in all Store~/Restore~ methods declared in the TcxCustomTreeList 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 Tree List state (both data layout and user interaction states) in an INI file.StoreToRegistry | RestoreFromRegistryAllow you to store the Tree List state (both data layout and user interaction states) in the system registry.StoreToStream | RestoreFromStreamAllow you to store the Tree List state (both data layout and user interaction states) in a stream.

Code Examples

Store Tree List 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 Tree List structure/data layout.

delphi
uses
  System.SysUtils, // Declares the FileExists function
  cxTL, // Declares TcxTreeList, TcxCustomTreeList, and related types
// ...

procedure TMyForm.FormCreate(Sender: TObject);
var
  AFileStream: TFileStream;
begin
  if FileExists('TreeListConfig.dat') then
  begin
    AFileStream := TFileStream.Create('TreeListConfig.dat', fmOpenReadWrite);
    try
      cxTreeList1.RestoreFromStream(AFileStream, True, False, '', cxTreeListStoreAllDataViewStates);
    finally
      AFileStream.Free;
    end;
  end;
end;

procedure TMyForm.FormDestroy(Sender: TObject);
var
  AFileStream: TFileStream;
begin
  AFileStream := TFileStream.Create('TreeListConfig.dat', fmCreate or fmOpenReadWrite);
  try
    cxTreeList1.StoreToStream(AFileStream, '', cxTreeListStoreAllDataViewStates);
  finally
    AFileStream.Free;
  end;
end;
cpp
#include "System.SysUtils.hpp" // Declares the FileExists function
#include "cxTL.hpp" // Declares TcxTreeList, TcxCustomTreeList, and related types

// Add the following linker directive to the corresponding CPP source file:
#pragma link "cxTL" // Required to use cxTL.hpp declarations

void __fastcall TMyForm::FormCreate(TObject *Sender)
{
  TFileStream *AFileStream;
  if(FileExists("TreeListConfig.dat"))
  {
    AFileStream = new TFileStream("TreeListConfig.dat", fmOpenReadWrite);
    try
    {
      cxTreeList1->RestoreFromStream(AFileStream, true, false, "", cxTreeListStoreAllDataViewStates);
    }
    __finally
    {
      delete AFileStream;
    }
  }
}

void __fastcall TMyForm::FormDestroy(TObject *Sender)
{
  TFileStream *AFileStream = new TFileStream("TreeListConfig.dat", fmCreate | fmOpenReadWrite);
  try
  {
    cxTreeList1->StoreToStream(AFileStream, "", cxTreeListStoreAllDataViewStates);
  }
  __finally
  {
    delete AFileStream;
  }
}

Restore User Interaction States After Data Refresh

The following code example restores selection, focus and scroll positions, and node expanded states after a refresh operation in the bound dataset:

delphi
uses
  FireDAC.Comp.Client, // Declares the TFDQuery component
  cxDBTL; // Declares the TcxDBTreeList class
// ...

  cxDBTreeList1.StoreDataViewState(cxTreeListStoreAllDataViewStates);
  FDQuery1.Refresh;
  cxDBTreeList1.RestoreDataViewState(cxTreeListStoreAllDataViewStates);
cpp
#include "FireDAC.Comp.Client.hpp" // Declares the TFDQuery component
#include "cxDBTL.hpp" // Declares the TcxDBTreeList 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 "cxDBTL" // Required to use cxDBTL.hpp declarations

  cxDBTreeList1->StoreDataViewState(cxTreeListStoreAllDataViewStates);
  FDQuery1->Refresh();
  cxDBTreeList1->RestoreDataViewState(cxTreeListStoreAllDataViewStates);

See Also

cxGridStoreAllDataViewStates Global Constant

cxTL Unit