加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi TreeView – 在运行时创建节点

发布时间:2020-12-15 03:50:16 所属栏目:大数据 来源:网络整理
导读:任何人都可以告诉我如何做以下事情: 创建节点 启用/禁用单个节点 我想知道如何在Application运行时执行上述操作,例如在Form的OnCreate事件中. 解决方法 添加节点: function FindRootNode(ACaption: String; ATreeView: TTreeView): TTreeNode; var LCount:
任何人都可以告诉我如何做以下事情:

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

我想知道如何在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并取消那里的选择.不太好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读