我试图在treeview中获取所选节点的所有子节点,但遇到了一些问题。
以这个treeview为例:

我想让所有的子节点变成黄色高亮显示的“文件夹”节点,这将是在它旁边有一条蓝线的子节点。
这就是我试过的:
procedure Form1.GetTreeChilds(ANode: TTreenode);
begin
while ANode <> nil do
begin
ListBox1.Items.Add(ANode.Text);
ANode := ANode.GetNext;
end;
end;它可以工作,但它也返回项目6,它不是子级的黄色高亮显示的“文件夹”。
为了只将子节点放到黄色的高级别文件夹中,我需要更改什么或不同的操作?
谢谢。
发布于 2014-12-13 20:51:54
试一试:
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;https://stackoverflow.com/questions/27463281
复制相似问题