数据库结构:
字段 类型
ID 整型 索引(无重复)
name 文本
father 整型
//tree初始化
procedure TForm1.FormActivate(Sender: TObject);
var i:integer;
begin
treeview1.Items.BeginUpdate;
while not(adotable1.Eof) do
begin
if ADOTable1.FieldValues['father']=0 then
treeview1.Items.addchild(treeview1.DropTarget,ADOTable1.FieldValues['name'])
else
begin
i:=0;
repeat
if treeview1.Items.Item[i].Text = ADOTable1.Lookup('ID',ADOTable1.FieldValues['father'],'name') then
begin
treeview1.Items.AddChild(treeview1.Items.Item[i],ADOTable1.FieldValues['name']);
break;
end;
i:=i+1;
until i>adotable1.RecordCount;
end;
ADOTable1.next;
end;
treeview1.Items.EndUpdate;
end;</
用数据表创建树
最新推荐文章于 2024-08-31 23:36:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)