数据库结构:
字段 类型
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-09-22 11:17:00 发布
这篇博客介绍如何利用数据库中的数据创建树形结构,通过遍历数据库记录,根据父子关系在Treeview中构建层次结构。同时,展示了添加、删除节点的操作,并在节点选择时更新与之关联的ListView列表。
摘要由CSDN通过智能技术生成