How to auto expand all TTreeView nodes?

20,835

Solution 1

You simply need to call FullExpand() on the tree view.

Solution 2

When adding treenode make its expanded property to true

you will find a property for the treeNode Object, set it yo true before add to list of nodes.

and also you can find a method for the treeView called ExpandAll

My Regards


try this code

//this will expand all nodes of Level and their parents
procedure ExpandTree(Tree: TTreeView; Level: integer);

  procedure ExpandParents(Node: TTreeNode);
  var
    aNode : TTreeNode;
  begin
    aNode := Node.Parent;
    while aNode <> nil do begin
      if not aNode.Expanded then
        aNode.Expand(false);
      aNode := aNode.Parent;
    end;
  end;

var
  aNode : TTreeNode;
begin
  if Tree.Items.Count > 0 then begin
    aNode := Tree.Items[0];

    while aNode <> nil do begin
      if aNode.Level = Level then begin
        aNode.Expand(false);
        ExpandParents(aNode);
      end;
      aNode := aNode.GetNext;
    end;
  end;
end;

//this will expand the Node and it's parents
procedure ExpandNode(Node: TTreeNode);
var
  aNode : TTreeNode;
begin
  Node.Expand(false);

  aNode := Node.Parent;
  while aNode <> nil do begin
    if not aNode.Expanded then
      aNode.Expand(false);
    aNode := aNode.Parent;
  end;
end;

and see the reference http://www.delphipages.com/forum/showthread.php?t=159148

My Regards

Share:
20,835

Related videos on Youtube

Funtime
Author by

Funtime

Updated on June 13, 2020

Comments

  • Funtime
    Funtime almost 4 years

    I want to expand tree on main form when application starts. How i can do it? I cant find corresponding property. C++ builder 2009.

  • Funtime
    Funtime about 13 years
    TTreeView don't have ExpandAll method. All objects to TreeViw was added in desing time
  • Marjan Venema
    Marjan Venema about 13 years
    On StackOverflow you do not need to use /pre or whatever to format code. All you need to do is indent it by four spaces. It would also help if you didn't use tabs but spaces to indent your statements. For inline code you can surround the code with "back quote" characters. The back quote (`) is usually found together with the tilde (~). The back quote can also be used in comments: like so.

Related