00 Votes

Delphi/Lazarus: Fully Expand or Collapse TreeView

Question by Guest | 2013-11-22 at 21:48

I am using a TTreeView in my program and I would like to write a function that automatically pops out all the items of the TreeView and another function that ensures that all branches are closed.

Various attempts to navigate through the TreeView and to use the Expand() command on several nodes have not led to a result.

I hope someone can help me here.

ReplyPositiveNegativeDateVotes
1Best Answer1 Vote

Nothing is easier than that. You do not have to care about a function navigating through all items.

Just use

TreeView1.FullExpand; 

to unfold all branches and

TreeView1.FullCollapse;

to close all branches again.
2013-11-25 at 13:13

ReplyPositive Negative
11 Vote

If you still want to use your Expand function, you can of course also do:

if TreeView1.Items[0] <> nil then
   TreeView1.Items[0].Expand(True);

Or:

if TreeView1.Items.GetFirstNode <> nil then 
   TreeView1.Items.GetFirstNode.Expand(True);

In case that the first item of the TreeView is set (otherwise there would be an exception), we are executing the Expand() operation on this first TreeView-Node. The "true" ensures that all other branches hanging on that node are expanded. If we pass "false", only the node is expanded, on which we have executed the Expand.
2013-11-26 at 22:08

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.