Toggle TreeView CheckBoxes
ndrew.virus, спасибо, но немного не то. Посмотрю, конечно, может чего там и найду
Вот что с утра, на свежую голову придумал
const
siUnchecked = 1;
siChecked = 2;
siGrayed = 3;
procedure ToggleCheckChildren(Node: TTreeNode);
var
I: Integer;
begin
for I := 0 to Node.Count - 1 do
begin
Node.Item[I].StateIndex := Node.StateIndex;
ToggleCheckChildren(Node.Item[I]);
end;
end;
procedure ToggleCheckParent(Node: TTreeNode);
var
P: TTreeNode;
I: Integer;
begin
P := Node.Parent;
if Assigned(P) then
begin
P.StateIndex := Node.StateIndex;
for I := 0 to P.Count - 1 do
if P.Item[I].StateIndex <> P.StateIndex then
begin
P.StateIndex := siGrayed;
Break;
end;
ToggleCheckParent(P);
end;
end;
procedure ToggleTreeViewCheckBoxes(Node: TTreeNode); overload;
begin
if Assigned(Node) then
begin
if Node.StateIndex = siUnchecked then
Node.StateIndex := siChecked
else
Node.StateIndex := siUnchecked;
ToggleCheckChildren(Node);
ToggleCheckParent(Node);
end;
end;
siUnchecked = 1;
siChecked = 2;
siGrayed = 3;
procedure ToggleCheckChildren(Node: TTreeNode);
var
I: Integer;
begin
for I := 0 to Node.Count - 1 do
begin
Node.Item[I].StateIndex := Node.StateIndex;
ToggleCheckChildren(Node.Item[I]);
end;
end;
procedure ToggleCheckParent(Node: TTreeNode);
var
P: TTreeNode;
I: Integer;
begin
P := Node.Parent;
if Assigned(P) then
begin
P.StateIndex := Node.StateIndex;
for I := 0 to P.Count - 1 do
if P.Item[I].StateIndex <> P.StateIndex then
begin
P.StateIndex := siGrayed;
Break;
end;
ToggleCheckParent(P);
end;
end;
procedure ToggleTreeViewCheckBoxes(Node: TTreeNode); overload;
begin
if Assigned(Node) then
begin
if Node.StateIndex = siUnchecked then
Node.StateIndex := siChecked
else
Node.StateIndex := siUnchecked;
ToggleCheckChildren(Node);
ToggleCheckParent(Node);
end;
end;