var
RootNode,SonNode:TcxTreeListNode;
qryRoot,qrySon:TADOQuery;
cxTreeList1.OptionsView.CheckGroups:=true;
cxTreeList1.Root.CheckGroupType:=ncgCheckGroup;
qryRoot:=TAdoQuery.create(nil);
qrySon:=TAdoQuery.create(nil);
qryRoot.Connection:=con1;
qrySon.Connection:=con1;
try
with qryRoot do
begin
Close;
SQL.Text:='SELECT DISTINCT PID,Caption FROM dbo.Parent';
Open;
qrySon.Close;
qrySon.SQL.Text:='SELECT PID,SID,Caption FROM dbo.Son ORDER BY PID,SID';
qrySon.Open;
cxTreeList1.Clear;
DisableControls;
while not eof do
begin
RootNode:=cxTreeList1.Add;
RootNode.CheckGroupType:=ncgCheckGroup;
RootNode.Texts[0]:=FieldByName('PID').AsString+'.'+FieldByName('Caption').AsString;
RootNode.Texts[1]:=FieldByName('PID').AsString;
RootNode.Enabled:=False;
with qrySon do begin DisableControls;
Filtered:=False;
Filter:='PID='+QuotedStr(FieldByName('PID').AsString);
Filtered:=True;
while not Eof do
begin
SonNode:=RootNode.AddChild;
SonNode.Texts[0]:=trim(FieldByName('SID').AsString)+'.'+FieldByName('Caption').AsString;
SonNode.Texts[1]:=trim(FieldByName('SID').AsString);
Next;
end;
EnableControls;
end;
Next;
end;
EnableControls;
end;
finally
qryRoot.Free;
qrySon.Free;
end;
实现 cxTreeList使用复选框实现多选 自动级联选择