Author: Tomas Rutkauskas
How to check if a TTreeView is fully expanded or collapsed
Answer:
1 2 function IsTreeviewFullyExpanded(tv: TTreeview): Boolean;
3 var4 node: TTreenode;
5 begin6 Assert(Assigned(tv));
7 if tv.items.count > 0 then8 begin9 node := tv.Items[0];
10 Result := true;
11 while Result and Assigned(node) do12 begin13 Result := node.Expanded ornot node.HasChildren;
14 node := node.GetNext;
15 end;
16 end17 else18 Result := false
19 end;
20 21 function IsTreeviewFullyCollapsed(tv: TTreeview): Boolean;
22 var23 node: TTreenode;
24 begin25 Assert(Assigned(tv));
26 if tv.items.count > 0 then27 begin28 node := tv.Items[0];
29 Result := true;
30 while Result and Assigned(node) do31 begin32 Result := not (node.Expanded and node.HasChildren);
33 node := node.GetNext;
34 end;
35 end36 else37 Result := false
38 end;