//添加一级结点
treeview1.items.clear;
treenode:=treeview1.items.add(nil,'各行政区划一览表');
with dm1 do
begin
query1.Close ;
query1.sql.Clear;
query1.sql.add('select dvs,cod from admd where cod like ''__0000'' order by dvs');
query1.open;
with TreeView1.Items do
begin
while not query1.eof do
begin
addchild(treenode,query1.fieldbyname('dvs').asstring);
query1.next;
end;
end;
end;//end with
//添加某个一级结点下的子结点
selnode:=treeview1.selected;
parentnode:=treeview1.selected.Parent ;
if not treeview1.selected.expanded then
begin
//若为根结点
if parentnode=nil then exit;
//若为二级结点且
if parentnode.parent=nil then
begin
if (not selnode.haschildren) then // 此时还没有添加三级结点
begin
with dm1 do
begin
query1.close;
query1.sql.clear;
query1.SQL.add('select * from admd where dvs like
dvs order by dvs');
query1.parambyname('pdvs').asstring:=''+treeview1.selected.text+'%'+'';
query1.open;
query1.next; //从第2个记录开始写,因为查找出的第一个记录为xx省
while not query1.eof do
begin
treeview1.items.addchild(selnode,query1.fieldbyname('dvs').asstring);
query1.next;
end;
end;//end dm1
edtsd.text:=selnode.text;
selnode.Expand (true);
end
else // 此时已经添加三级结点
edtsd.text:=selnode.text;
end
else
if (not selnode.haschildren) then edtsd.text:=selnode.text //若为三级结点
end
else
if parentnode<>nil then edtsd.text:=selnode.text;
//使结点关闭
treeview1.FullCollapse;