我有个模块中要用到树控件,在树中有多个一级,二级节点.在窗体创建时从表中读取这些节点,如果是只有一个父节点,多个子节点的话可以实现动态添加到树中,可是如果有多个父节点(一级节点),同时每个父节点中又有多个子节点时要怎么让程序从表中添加进去????比如说,有三个城市:
深圳(福田,罗源,南山,龙岗,宝安)
广州(天河,东山,越秀,珠海,白云)
东莞(厚街,长安,东城,南城,白濠) 括号中的为二级节点.
这是只有一个父节点时的添加方法:
adodataset1.Active:=true;
adoquery1.Active:=true;
ado_tmp:=Tadoquery.Create(nil);
ado_tmp.Connection :=DataModule1.ADOConnection1;
ado_tmp.SQL.text:='select distinct Bumen_name from organization';
ado_tmp.open;
while not ado_tmp.eof do
begin
newtree:=treeview1.TopItem ; TreeView1.items.AddChild(newtree,ado_tmp.fieldbyname('Bumen_name').asstring); ado_tmp.next;
end;
深圳(福田,罗源,南山,龙岗,宝安)
广州(天河,东山,越秀,珠海,白云)
东莞(厚街,长安,东城,南城,白濠) 括号中的为二级节点.
这是只有一个父节点时的添加方法:
adodataset1.Active:=true;
adoquery1.Active:=true;
ado_tmp:=Tadoquery.Create(nil);
ado_tmp.Connection :=DataModule1.ADOConnection1;
ado_tmp.SQL.text:='select distinct Bumen_name from organization';
ado_tmp.open;
while not ado_tmp.eof do
begin
newtree:=treeview1.TopItem ; TreeView1.items.AddChild(newtree,ado_tmp.fieldbyname('Bumen_name').asstring); ado_tmp.next;
end;
父节点的添加:TreeView1.Items.AddChild(nil, Edit1.Text);
子节点的添加:TreeView1.Items.AddChild(CurrentNode, Edit1.Text);(CurrentNode是已经存在的节点)
这是什么东东??没见过哦~~