How to check if a TTreeView is fully expanded or collapsed #90

function IsTreeviewFullyExpanded(tv: TTreeview): Boolean;
var
  node: TTreenode;
begin
  Assert(Assigned(tv));
  if tv.items.count > 0 then
  begin
    node := tv.Items[0];
    Result := true;
    while Result and Assigned(node) do
    begin
      Result := node.Expanded or not node.HasChildren;
      node := node.GetNext;
    end;
  end
  else
    Result := false
end;

function IsTreeviewFullyCollapsed(tv: TTreeview): Boolean;
var
  node: TTreenode;
begin
  Assert(Assigned(tv));
  if tv.items.count > 0 then
  begin
    node := tv.Items[0];
    Result := true;
    while Result and Assigned(node) do
    begin
      Result := not (node.Expanded and node.HasChildren);
      node := node.GetNext;
    end;
  end
  else
    Result := false
end;
Original resource: The Delphi Pool
Author: Peter Below
Added: 2009/08/24
Last updated: 2009/08/24