//这是函数
Procedure TFrmCaseAcceptBytenability.NodeParent(TreeView:TTreeView;Node:TTreeNode;StIndex:integer);
var
i,j:integer;
isAll,isChecked:Boolean;
ParentNode:TTreeNode;
begin
isAll:=True;
isChecked:=False;
For i:=0 to TreeView.Items.Count-1 do
begin
if TreeView.Items.Item = Node then
begin
ParentNode:=TreeView.Items.Item.Parent;
if ParentNode<>nil then
begin
if ((ParentNode.StateIndex<>2) and (ParentNode.StateIndex<>3))
and (StIndex<>2) then Break; //夫节点未被选中 且选中节点被取消选则 跳出
For j:=0 to ParentNode.Count-1 do
begin
if (parentNode.Item[j].StateIndex=1) or (parentNode.Item[j].StateIndex=3) then
isAll:=False;
if (ParentNode.Item[j].StateIndex=2) or (parentNode.Item[j].StateIndex=3) then
isChecked:=True;
end; //For j:=0 to ParentNode.Count-1 do
if isAll then
parentNode.StateIndex:=2
else begin
if isChecked then
ParentNode.StateIndex:=3
else
ParentNode.StateIndex:=1;
end;
NodeParent(TreeView,parentNode,StIndex);
end; //if ParentNode<>nil then
end; //if TreeView.Items.Item = Node then
end; //For i:=0 to TreeView.Items.Count-1 do
end;
//这是函数调用
procedure TFrmCaseAcceptBytenability.TreeView1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
MyHitTest : THitTests;
node: TTreeNode;
begin
node := TreeView1.GetNodeAt(x,y);
MyHitTest := TreeView1.GetHitTestInfoAt(X,Y);
if htOnStateIcon in MyHitTest then
begin
if node.StateIndex = 2 then
begin
node.StateIndex := 1;
NodeChild(Node,1);
NodeParent(TreeView1,Node,1);
end
else begin
node.StateIndex := 2;
NodeChild(Node,2);
NodeParent(TreeView1,Node,2);
end;
end;
end;