unit Unit1;
{$mode DELPHI}
interface
uses
Classes, SysUtils, FileUtil, VirtualTrees, Forms, Controls, Graphics, Dialogs,
StdCtrls,ExtCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Panel1: TPanel;
VST: TVirtualStringTree;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure VSTAfterCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
const CellRect: TRect);
private
{ private declarations }
public
{ public declarations }
end;
type
PTreeData = ^TTreeData;
TTreeData =
record
NodeName :
String;
// Eindeutige Bezeichnung
Panel : TPanel;
end;
var
Form1: TForm1;
Node : PVirtualNode;
Data: PTreeData;
implementation
{$R *.lfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
VST.NodeDataSize:=SizeOf(TTreeData);
VST.DefaultNodeHeight:=50;
end;
procedure TForm1.VSTAfterCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
const CellRect: TRect);
begin
Data := VST.GetNodeData(Node);
If Assigned(Data)
Then begin
Data^.Panel.Left:=20;
Data^.Panel.Width:=CellRect.Right-CellRect.Left-Data^.Panel.Left;
Data^.Panel.Top:=CellRect.Top;
Data^.Panel.Height:=CellRect.Bottom-CellRect.Top;
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
VST.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Node := VST.AddChild(
nil);
If VST.AbsoluteIndex(Node) > -1
then begin
Data := VST.GetNodeData(Node);
Data^.NodeName:='
Nodename';
Data^.Panel:= TPanel.Create(
nil);
Data^.Panel.Parent := VST;
Data^.Panel.Left := 40;
Data^.Panel.Top := 0;
Data^.Panel.Width := 50;
Data^.Panel.Height := VST.DefaultNodeHeight;
Data^.Panel.Anchors := [akTop,akLeft];
Data^.Panel.BorderWidth := 0;
Data^.Panel.Autosize:=True;
Data^.Panel.Color:=clRed;
Data^.Panel.Visible:=True;
end;
end;
end.