2.按照层次建树,(数据表中有一个字段记录每一个节点在数上的深度,先建根节点,再第一层,第二层)
procedure TForm1.createtree(Sender: TObject);
var
sqlstr:string;
i:Integer;
rootnode,parentnode:TTreeNode;
begin
adoquery1.Close;
ADOQuery1.SQL.Clear;
sqlstr:=''select * from tdepart order by depth'';
ADOQuery1.SQL.Add(sqlstr);
ADOQuery1.Open;
ADOQuery1.First;
while not ADOQuery1.Eof do
begin
if ADOQuery1.fieldbyname(''parentid'').Asinteger = 0 then
rootnode:=tv1.Items.addchildobject(nil,trim(ADOQuery1.fieldbyname(''departname'').AsString),
pointer(ADOQuery1.fieldbyname(''id'').Asinteger))
else
begin
i:=0;
parentnode:=nil;
&n