Did you try FullExpand/FullCollapse?
I've just tried FullExpand but I'm obviously not using it correctly as the program hangs. added it in both the form Activate and Create procedures, hangs in both, no compile errors.
If the tree structure is big, full expand will take time. If you wish to expand only level x nodes, you can try something like this:
var
I: Integer;
Len: Integer;
NodeToExpand: array of TTreeNode;
begin
NodeToExpand := nil;
for I := 0 to ShellTreeView1.Items.Count - 1 do
begin
if ShellTreeView1.Items.Item[I].Level = 1 then
begin
Len := Length(NodeToExpand);
SetLength(NodeToExpand, Len + 1);
NodeToExpand[Len] := ShellTreeView1.Items.Item[I];
end;
end;
for I := Low(NodeToExpand) to High(NodeToExpand) do
NodeToExpand[I].Expand(False);
end;
In the above example the level is 1, but you can change it according to your needs.