cxTreeListStoreAllDataViewStates Constant
Declaration
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 | 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 Tree List state (both data layout and user interaction states) in an INI file.
- StoreToRegistry | RestoreFromRegistry
- Allow you to store the Tree List state (both data layout and user interaction states) in the system registry.
- StoreToStream | RestoreFromStream
- Allow 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.
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;
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:
uses
FireDAC.Comp.Client, // Declares the TFDQuery component
cxDBTL; // Declares the TcxDBTreeList class
// ...
cxDBTreeList1.StoreDataViewState(cxTreeListStoreAllDataViewStates);
FDQuery1.Refresh;
cxDBTreeList1.RestoreDataViewState(cxTreeListStoreAllDataViewStates);
See Also