gpt4 book ai didi

delphi TreeView - 在运行时创建节点

转载 作者:行者123 更新时间:2023-12-03 14:42:35 25 4
gpt4 key购买 nike

谁能告诉我如何执行以下操作:

  • 创建节点
  • 启用/禁用单个节点

我想知道如何在应用程序运行时执行上述操作,例如在表单的 OnCreate 事件中。

最佳答案

@Remus,这里有一个添加节点的简单示例。

添加根节点(0级)

Var
Node : TTreeNode;
begin
//function TTreeNodes.Add(Sibling: TTreeNode; const S: string): TTreeNode;
Node:=TreeView1.Items.Add(nil,'My Root Node') ;
Node.ImageIndex:=0;//now you can change any property of the node
end;

添加子节点(级别 > 0)

//in this case we add a child node in the current selected node.
Var
Node : TTreeNode;
begin
if TreeView1.Selected= nil then exit;
Node:=TreeView1.Items.AddChild(TreeView1.Selected,'My Child Node') ;
Node.ImageIndex:=0;//now you can change any property of the node
end;

添加多个节点

if you wanna add many nodes using a loop or something else you must use BeginUpdate before making the changes to the treeview. When all changes are complete, call EndUpdate to show the changes on screen. BeginUpdate and EndUpdate prevent excessive redraws and speed up processing time when nodes are added, deleted, or inserted.

Var
Node : TTreeNode;
i : Integer;
begin
TreeView1.Items.BeginUpdate;
try
for i:=1 to 100 do
begin
Node:=TreeView1.Items.Add(nil,'My Root Node '+IntToStr(i)) ;
Node.ImageIndex:=0;
end;
finally
TreeView1.Items.EndUpdate;
end;
end;

关于禁用节点,不存在类似的属性。

关于delphi TreeView - 在运行时创建节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2163248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com