早上刚做了一个treeview的一个过程,贴上你可研究一下就明白了
注:我用的三层结构)
procedure TF_xlgl_Main.get_fxry;
var
node_root,node_1,node_2,leaf: Ttreenode;
begin
TreeView1.Items.Clear;
node_root := TreeView1.Items.Add(nil,'访销部');
node_1 := TreeView1.Items.AddChild(node_root,'已分配线路的人员');
with F_xlgl_Main.CDS_Temp do
begin
Active := false;
CommandText := '';
CommandText := 'select a.FXRY00,COUNT(a.FXRY00) AS Num,b.RYMC00 '
+ 'from GSTKHGL0 a,GSTRYGL0 b '
+ 'where a.FXRY00=b.RYDM00 and a.GSDW00=b.GSDW00 '
+ 'group by FXRY00,RYMC00';
Active := true;
while not cds_temp.Eof do
begin
node_2 := TreeView1.Items.AddChild(node_1,fieldbyname('RYMC00').Value
+ '(共有客户数:'+inttostr(fieldbyname('Num').Value)+')');
/////////////////一下为与名称相同的人员所管辖的线路(做的二次循环)
with F_xlgl_Main.CDS_CTemp do
begin
Active := false;
CommandText := '';
CommandText := 'select a.FXXL00,COUNT(a.FXXL00) AS Num,b.XLMC00 '
+ 'from GSTKHGL0 a,GSTXLGL0 b where a.FXXL00=b.XLDM00 and a.GSDW00=b.GSDW00 '
+ 'and a.FXRY00='''+CDS_Temp.fieldbyname('FXRY00').Value+''' '
+ 'group by FXXL00,XLMC00';
Active := true;
while not cds_Ctemp.eof do
begin
leaf := TreeView1.Items.AddChild(node_2,fieldbyname('XLMC00').AsString);
//+ '(此线路共有客户数:'+inttostr(fieldbyname('Num').Value)+')');
Next;
end;
end;
Next;
end;
node_1 := TreeView1.Items.AddChild(node_root,'未分配线路的人员');
with CDS_Temp do
begin
Active := false;
CommandText := '';
CommandText := 'select count(*) as Num from GSTKHGL0 where FXRY00 is null';
Active := true;
node_1 := TreeView1.Items.AddChild(node_root,'未分配人员的客户('+inttostr(fieldbyname('Num').Value)+')');
end;
end;
end;