任何人都可以告诉我如何做以下事情:
>创建节点
>启用/禁用单个节点
我想知道如何在Application运行时执行上述操作,例如在Form的OnCreate事件中.
解决方法
添加节点:
function FindRootNode(ACaption: String; ATreeView: TTreeView): TTreeNode; var LCount: Integer; begin result := nil; LCount := 0; while (LCount < ATreeView.Items.Count) and (result = nil) do begin if (ATreeView.Items.Item[LCount].Text = ACaption) and (ATreeView.Items.Item[LCount].Parent = nil) then result := ATreeView.Items.Item[LCount]; inc(LCount); end; end; ... var LDestNode: TTreeNode; begin LDestNode := FindRootNode('category',TreeView1); if LDestNode <> nil then begin TreeView1.Items.AddChild(LDestNode,'node1'); TreeView1.Items.AddChild(LDestNode,'node2'); end; end;
(另见http://msdn.microsoft.com/en-us/library/70w4awc4.aspx)
消除节点
据我所知,没有办法禁用TreeNode.你唯一能做的就是拦截beforeSelect-event并取消那里的选择.不太好.