1,定义公共树节点node——select andselect_index,用来保存当前选中节点

casecadechecks设为false

2.方法如下

stateindex = 1代表没选中,stateindex = 2,代表选中

tree_checker.ItemState[i] := csUnknown代表没有选择框。

procedure Tfrm_w_checker.tree_checkerClick(Sender: TObject);
var
  i:integer;
  flag :string;
begin
  node_select := tree_checker.Selected;
  i := node_select.AbsoluteIndex;
  if (node_select.Level = 1) then
  begin
    node_select.StateIndex := 2;
    doctor := PNodedata(node_select.Data)^.doctor;
  end;
  if (node_select.Level = 1) and (node_select.StateIndex = 2) then
  begin
    if (select_index <> 0) and (select_index <> node_select.AbsoluteIndex) then
    begin
      tree_checker.Items[select_index].StateIndex := 1;
    end;
    select_index := node_select.AbsoluteIndex;
  end;
  for i := 0 to tree_checker.Items.Count - 1 do
  begin
    if tree_checker.Items[i].Level = 0 then
      tree_checker.ItemState[i] := csUnknown;
  end;
end;