Recent

Author Topic: [SOLVED]tshelltreeview how to fully expand the tree  (Read 1378 times)

petevick

  • Sr. Member
  • ****
  • Posts: 347
[SOLVED]tshelltreeview how to fully expand the tree
« on: February 02, 2022, 12:23:04 pm »
I'm just looking at the TShellTreeView control for possible use in a project. The first thing I've come across is that there doesn't seem to be a property to expand the tree as you would see in Linux Nemo for example. There is an AutoExpand property but that is for when a user clicks on a node.
There must be some way to expand the tree, but even Google has let me down. :(
« Last Edit: February 02, 2022, 01:37:19 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: tshelltreeview how to fully expand the tree
« Reply #1 on: February 02, 2022, 12:36:49 pm »
I'm just looking at the TShellTreeView control for possible use in a project. The first thing I've come across is that there doesn't seem to be a property to expand the tree as you would see in Linux Nemo for example. There is an AutoExpand property but that is for when a user clicks on a node.
There must be some way to expand the tree, but even Google has let me down. :(
Did you try FullExpand/FullCollapse?

petevick

  • Sr. Member
  • ****
  • Posts: 347
Re: tshelltreeview how to fully expand the tree
« Reply #2 on: February 02, 2022, 12:43:45 pm »
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.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: tshelltreeview how to fully expand the tree
« Reply #3 on: February 02, 2022, 12:51:40 pm »
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:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3.   Len: Integer;
  4.   NodeToExpand: array of TTreeNode;
  5. begin
  6.   NodeToExpand := nil;
  7.   for I := 0 to ShellTreeView1.Items.Count - 1 do
  8.   begin
  9.     if ShellTreeView1.Items.Item[I].Level = 1 then
  10.     begin
  11.       Len := Length(NodeToExpand);
  12.       SetLength(NodeToExpand, Len + 1);
  13.       NodeToExpand[Len] := ShellTreeView1.Items.Item[I];
  14.     end;
  15.   end;
  16.   for I := Low(NodeToExpand) to High(NodeToExpand) do
  17.     NodeToExpand[I].Expand(False);  
  18. end;

In the above example the level is 1, but you can change it according to your needs.

petevick

  • Sr. Member
  • ****
  • Posts: 347
Re: tshelltreeview how to fully expand the tree
« Reply #4 on: February 02, 2022, 01:36:53 pm »
[
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:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3.   Len: Integer;
  4.   NodeToExpand: array of TTreeNode;
  5. begin
  6.   NodeToExpand := nil;
  7.   for I := 0 to ShellTreeView1.Items.Count - 1 do
  8.   begin
  9.     if ShellTreeView1.Items.Item[I].Level = 1 then
  10.     begin
  11.       Len := Length(NodeToExpand);
  12.       SetLength(NodeToExpand, Len + 1);
  13.       NodeToExpand[Len] := ShellTreeView1.Items.Item[I];
  14.     end;
  15.   end;
  16.   for I := Low(NodeToExpand) to High(NodeToExpand) do
  17.     NodeToExpand[I].Expand(False);  
  18. end;

In the above example the level is 1, but you can change it according to your needs.
Thanks for that, it's exactly what I was looking for  ;)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: [SOLVED]tshelltreeview how to fully expand the tree
« Reply #5 on: February 02, 2022, 01:47:39 pm »
@petevick
Quote
Thanks for that, it's exactly what I was looking for 
You are welcome! You can speed up things with beginupdate/endupdate. See attached project form more details.

 

TinyPortal © 2005-2018