unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Contnrs, StdCtrls, VirtualTrees;
type
TNodeDataClass =
class
private
FSpalte1:
string;
FSpalte2:
string;
FSpalte3: Integer;
public
property Spalte1:
string read FSpalte1
write FSpalte1;
property Spalte2:
string read FSpalte2
write FSpalte2;
property Spalte3: Integer
read FSpalte3
write FSpalte3;
end;
PTreeData = ^TTreeData;
TTreeData =
record
FObject : TObject;
end;
TForm1 =
class(TForm)
vst: TVirtualStringTree;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure vstInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
procedure vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
private
{ Private-Deklarationen }
DataList: TObjectList;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Node: PVirtualNode;
begin
VST.NodeDataSize := SizeOf(TTreeData);
VST.RootNodeCount := DataList.Count;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
NodeData: TNodeDataClass;
begin
DataList := TObjectList.Create;
for i := 0
to 3
do
begin
NodeData := TNodeDataClass.Create;
NodeData.Spalte1 := IntToStr(i);
NodeData.Spalte2 := '
Spalte '+IntToStr(i);
NodeData.Spalte3 := i;
DataList.Add(NodeData);
end;
end;
procedure TForm1.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
var
data: PTreeData;
begin
data:= Sender.GetNodeData(Node);
case Column
of
0: CellText := TNodeDataClass(data^.FObject).FSpalte1;
1: CellText := TNodeDataClass(data^.FObject).FSpalte2;
2: CellText := IntToStr(TNodeDataClass(data^.FObject).FSpalte3);
end;
end;
procedure TForm1.vstInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var
data: PTreeData;
begin
data := Sender.GetNodeData(Node);
data^.FObject := DataList[Node.
Index];
end;
end.