I haven't been able to find a good example using the TVirtualDrawTree so I'm stumbling in the dark. This simple example I've put together has a record with only the one Caption:string. Here's how I'm adding root and child records...seems to be working:
procedure TForm.VDTaddClick(Sender: TObject);
var
Data: PMyRec;
Node: PVirtualNode;
begin
with VDT do
case (Sender as TButton).Tag of
0:
begin // add to root
Node := VDT.AddChild(nil);
Data := VDT.GetNodeData(Node);
Data^.Caption := 'Root ' + IntToStr(RootNodeCount);
end;
1: if Assigned(FocusedNode) then // add as child
begin
ChildCount[FocusedNode] := ChildCount[FocusedNode] + 1;
Expanded[FocusedNode] := True;
InvalidateToBottom(FocusedNode);
Node := VDT.AddChild(nil);
Data := VDT.GetNodeData(Node);
Data^.Caption := 'Child ' + IntToStr(RootNodeCount);
// Data^.Caption := 'Child ' + IntToStr(Node.Index);
end;
end;
end;
When I display the tree with this, you can see, in the attachment, that the tree indentions seem to be correct but the text is showing up at the bottom, like a main root record rather than a child record.
procedure TForm.VDTDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
var
Data: PMyRec;
R: TRect;
I, w: integer;
s, s1: string;
begin
with Sender as TVirtualDrawTree, PaintInfo do
begin
Data := VDT.GetNodeData(Node);
SetBKMode(Canvas.Handle, TRANSPARENT);
R := ContentRect;
if vsSelected in Node^.States then
Canvas.Font.Color := clWhite
else
Canvas.Font.Color := clBlack;
s := Data^.Caption;
DrawText(Canvas.Handle, PChar(s), Length(s), R, DT_LEFT or
DT_BOTTOM or DT_SINGLELINE);
end;
end;
Can someone provide help or a good VDT example?