Link to home
Start Free TrialLog in
Avatar of Miguel Oz
Miguel OzFlag for Australia

asked on

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.
Avatar of Mahdi78
Mahdi78
Flag of Algeria image

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

TreeView.FullExpand;

(and TreeView.FullCollapse for the opposite)
ASKER CERTIFIED SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Miguel Oz

ASKER

It works. Call it after EndUpdate