• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3800
  • Last Modified:

How to expand all nodes in a virtual tree (TVirtualStringTree)

I have a virtual tree with the following information:
- My node sample
  - Folder 1
     - File 1
     - File 2
     - Folder 2
       - File 2.1

I have already defined OnInitNode and OnInitChildren so that the contents are rendered OK from my folder container.

If at startup I run this method
procedure TWndDynamicHierarchy.InitialiseHierarchyTreeView;
begin
  VstHierarchy.RootNodeCount := 1;
  VstHierarchy.Expanded[VstHierarchy.RootNode] := TRUE;
end;
My form is showing me only one node not expanded.
+ My node sample
instead of the whole expanded tree.

How can my code expand all nodes after running InitialiseHierarchyTreeView (This is running within a begin/end update)

Note: I need the nodes expanded only the first time. InitialiseHierarchyTreeView  is run only once before a form is shown.
0
Miguel Oz
Asked:
Miguel Oz
  • 2
1 Solution
 
Mahdi78Commented:
I don't have VirtualTree, but you can expend and collapse all node with TTreeView by the following way

Expand

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  for I := 0 to TreeView1.Items.Count - 1 do
  begin
  TreeView1.Items[I].Expand(True);
  end;

end;

collapse

procedure TForm1.Button2Click(Sender: TObject);
var i : integer;
begin
  for I := 0 to TreeView1.Items.Count - 1 do
  begin
  TreeView1.Items[I].Collapse(True);
  end;
end;
0
 
epasquierCommented:
in TTreeView, there is a simplest way to do that :

TreeView.FullExpand;

(and TreeView.FullCollapse for the opposite)
0
 
epasquierCommented:
It would appear that FullExpand and FullCollapse exist also for TVirtualStringTree
0
 
Miguel OzSoftware EngineerAuthor Commented:
It works. Call it after EndUpdate
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now