procedure TFrmMenuNodeData.TreeView1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
T: TTreeNode;
TI: THitTests;
i: integer;
begin
T := TTreeView(Sender).GetNodeAt(X, Y);
TI := TTreeView(Sender).GetHitTestInfoAt(X,Y);
if (T<>nil) and (htOnItem in TI) then
begin
TTreeView(Sender).Items.BeginUpdate;
if T.StateIndex=1 then
begin
SetTVState(T, 2);
end else begin
SetTVState(T, 1);
end;
for i:=0 to TTreeView(Sender).Items.Count-1 do
begin
if TTreeView(Sender).Items.Level<=0 then
RefreshTVState(TTreeView(Sender).Items);
end;
TTreeView(Sender).Items.EndUpdate;
end;
end;
procedure TFrmMenuNodeData.SetTVState(Node: TTreeNode; StateIndex: integer);
var
i: integer;
begin
Node.StateIndex := StateIndex;
for i:=0 to Node.Count-1 do
if Node.Item.HasChildren then
SetTVState(Node.Item, StateIndex)
else
Node.Item.StateIndex := StateIndex;
end;