_pNodeData := VST.GetNodeData(PVN);
if Assigned(_pNodeData) then
ShowMessage(_pNodeData.Name);
PVN := VST.GetNextSibling(PVN);
*遍历所有节点:
VST.IterateSubtree(nil,VSTIterateProc,nil,[]);
procedure TForm1.VSTIterateProc(Sender: TBaseVirtualTree;
Node: PVirtualNode; Data: Pointer; var Abort: Boolean);
_pNodeData:PTagCustomListItem;
begin
_pNodeData := Sender.GetNodeData(Node);
if Assigned(_pNodeData) then
ShowMessage(_pNodeData.Name);
*增加根节点:
_count := VST.RootNodeCount ;
VST.RootNodeCount := _count + 1;
**增加子节点:
_count: Cardinal;
begin
// add as child
_count := VST.ChildCount[VST.FocusedNode];
VST.ChildCount[VST.FocusedNode] := _count + 1 ;
VST.Expanded[VST.FocusedNode] := True;
VST.InvalidateToBottom(VST.FocusedNode);
*另一种添加节点方法:
procedure TForm1.FormCreate(Sender: TObject);
Data:PTagCustomListItem;
RootNode:PVirtualNode;
begin
//清除所有Node
VirtualStringTree1.Clear;
//指定VitrualStringTree有幾個Node
//VirtualStringTree1.RootNodeCount := 2;
//將所定義的結構大小指定給VitualStringTree
VirtualStringTree1.NodeDataSize := SizeOf(TTagCustomListItem);
//添加节点
RootNode:= VirtualStringTree1.AddChild(nil);
Data:=VirtualStringTree1.GetNodeData(RootNode);
Data^.Name:='根结点';
RootNode:= VirtualStringTree1.AddChild(nil);
Data:=VirtualStringTree1.GetNodeData(RootNode);
Data^.Name:='根结点aaa';
*必须的回调函数:
procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
_pNodeData:PTagCustomListItem;
begin
_pNodeData := Sender.GetNodeData(Node);
if Assigned(_pNodeData) then
CellText := _pNodeData.Name;
procedure TForm1.VSTInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
_pNodeData:PTagCustomListItem;
begin
_pNodeData := Sender.GetNodeData(Node);
if Assigned(_pNodeData) then
_pNodeData.Name := Format('Node Level:%d, Index:%d ',[Sender.GetNodeLevel(Node),Node.Index]);
http://peirenlei.iteye.com/blog/487207自定义结点结构:PTagCustomListItem = ^TTagCustomListItem ; TTagCustomListItem = record Name:string; Id:Integer; end; *初始化:VST.NodeDataSize := SizeOf(TTagCustomListItem); VST.RootNodeCount := 2; *遍历根
VST1: TVirtualStringTree;
//按钮公用函数,根据不同 标签tag区分,
Screen.Cursor := crHourGlass; //设置屏幕鼠标的形状为crhourGlass
with VST1 do
Start := GetTickCount; // Start: Cardinal;
case (Sender a...
VirtualStringTreeDrawText(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
const Text: string; const CellRect: TRect; var DefaultDraw: Boolean);
在此事件中进行自绘,并将DefaultDraw设置未false,即可。