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.
LVL 36
Miguel OzSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Emmanuel PASQUIERFreelance Project ManagerCommented:
in TTreeView, there is a simplest way to do that :

TreeView.FullExpand;

(and TreeView.FullCollapse for the opposite)
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
It would appear that FullExpand and FullCollapse exist also for TVirtualStringTree
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Miguel OzSoftware EngineerAuthor Commented:
It works. Call it after EndUpdate
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.