L
lijucheng8
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我用delphi 写的显示树状图的代码,只能显示一个部门,不知那里错了: qryexec(qry1,'select * from bumen order by bmm'); TreeView1.Items.Clear ; //TreeView1是中文,TreeView2是ID,隐藏的 TreeView2.Items.Clear ; inittree(qry1,TreeView1,TreeView2,0,true);procedure inittree(qry:tadoquery;treeview:ttreeview;treeview1:ttreeview;parentid:integer;isExpanded:boolean);var i:integer; MyTreeNode,MyTreeNode1: TTreeNode; tmpqry:tadoquery; abc:string;begin if parentid=0 then begin MyTreeNode:=treeview.Items.Add(nil,'所有部门'); MyTreeNode.SelectedIndex :=1; MyTreeNode1:=treeview1.Items.Add(nil,'id部门'); MyTreeNode1.SelectedIndex :=1; end; tmpqry:=tadoquery.Create(nil); tmpqry:=qry; tmpqry.Filter:='dirid='''+inttostr(parentid)+''''; tmpqry.Filtered:=true; while not tmpqry.Eof do begin MyTreeNode:=treeview.Items.AddChild(MyTreeNode,tmpqry.fieldbyname('bm').asstring); MyTreeNode1:=treeview1.Items.AddChild(MyTreeNode1,tmpqry.fieldbyname('id').asstring); MyTreeNode.SelectedIndex:=1; MyTreeNode1.SelectedIndex:=1; inittree(tmpqry,treeview,treeview1,tmpqry.fieldbyname('id').AsInteger ,true); tmpqry.Next; end;end;