选择所有根节点或所有子节点

选择所有根节点或所有子节点

本文介绍了如何在VirtualStringTree中选择所有根节点或所有子节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想选择所有根节点或所有子节点(不是VirtualTreeView中的所有节点).
我尝试使用此代码选择所有根节点:

I would like to select either all root nodes or all child nodes (not all nodes in a VirtualTreeView).
I've tried to use this code to select all root nodes:

procedure SelectAllRoots;
var
  Node: PVirtualNode;
begin
  Form1.VirtualStringTree1.BeginUpdate;
  Node := Form1.VirtualStringTree1.GetFirst;
  while True do
  begin
    if Node = nil then
      Break;
    if not (vsSelected in Node.States) then
      Node.States := Node.States + [vsSelected];
    Node := Form1.VirtualStringTree1.GetNext(Node);
  end;
  Form1.VirtualStringTree1.EndUpdate;
end;

我可以说有一个小故障.选择不完整或卡住了.我在做什么错了?

I can tell there's a small glitch.The selection is either incomplete or gets stuck. What am I doing wrong ?

修改:
我使用的是MultiSelection.


I use MultiSelection.

推荐答案

1.选择所有根节点:

1. Select all root nodes:

要选择所有根节点,可以使用以下过程:

To select all root nodes, you can use the following procedure:

procedure SelectRootNodes(AVirtualTree: TBaseVirtualTree);
var
  Node: PVirtualNode;
begin
  AVirtualTree.BeginUpdate;
  try
    Node := AVirtualTree.GetFirst;
    while Assigned(Node) do
    begin
      AVirtualTree.Selected[Node] := True;
      Node := AVirtualTree.GetNextSibling(Node);
    end;
  finally
    AVirtualTree.EndUpdate;
  end;
end;

2.选择所有子节点:

2. Select all child nodes:

要选择所有级别独立的子节点,您需要使用以下递归函数:

To select all child nodes, level independent, you need to use recursive function like this:

procedure SelectChildNodes(AVirtualTree: TBaseVirtualTree);
var
  Node: PVirtualNode;

  procedure SelectSubNodes(ANode: PVirtualNode);
  var
    SubNode: PVirtualNode;
  begin
    SubNode := AVirtualTree.GetFirstChild(ANode);
    while Assigned(SubNode) do
    begin
      SelectSubNodes(SubNode);
      AVirtualTree.Selected[SubNode] := True;
      SubNode := AVirtualTree.GetNextSibling(SubNode);
    end;
  end;

begin
  AVirtualTree.BeginUpdate;
  try
    Node := AVirtualTree.GetFirst;
    while Assigned(Node) do
    begin
      SelectSubNodes(Node);
      Node := AVirtualTree.GetNextSibling(Node);
    end;
  finally
    AVirtualTree.EndUpdate;
  end;
end;

这篇关于如何在VirtualStringTree中选择所有根节点或所有子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:02