获取选定的TTreeview子级 [英] Getting Selected TTreeview Children

查看:76
本文介绍了获取选定的TTreeview子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在树视图中获取所选节点的所有子节点,但遇到了一些问题。

I am trying to get all child nodes of the selected node in a treeview but have run into a few problems.

以该树视图为例:

我希望将所有子节点变为黄色突出显示的文件夹节点,该子节点将是旁边带有蓝线的子节点。

I want to get all nodes that are child to yellow highlighted "Folder" node, which would be the child nodes with a blue line next to it.

这是我尝试过的:

procedure Form1.GetTreeChilds(ANode: TTreenode);
begin
  while ANode <> nil do
  begin
    ListBox1.Items.Add(ANode.Text);
    ANode := ANode.GetNext;
  end;
end;

它起作用,除了它还会将不是子项的第6项返回到突出显示的黄色文件夹中。

It works except that it also returns Item 6 which is not child to the yellow highlighted "Folder".

我仅需将子节点移到黄色的高亮文件夹中,需要更改或采取其他措施?

What do I need to change or do differently to only get the child nodes to the yellow highligted Folder?

谢谢。

推荐答案

请尝试以下操作:

procedure Form1.GetTreeChilds(ANode: TTreeNode);
begin
  ANode := ANode.GetFirstChild;
  if ANode = nil then Exit;
  ListBox1.Items.BeginUpdate;
  try
    repeat
      ListBox1.Items.Add(ANode.Text);
      GetTreeChilds(ANode);
      ANode := ANode.GetNextSibling;
    until ANode = nil;
  finally
    ListBox1.Items.EndUpdate;
  end;
end;

这篇关于获取选定的TTreeview子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆