用 SQL数据库 怎样在TreeView1 中显示出来,层次为章、节、段
帮帮忙
比如:
var
treenode1,treenode2,treenode3:ttreenode;
i:integer;
fieldname:string;
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select distinct 章号 from 段');
adoquery1.Open;
treeview1.Items.Clear;
//添加根目录
treenode1:=treeview1.Items.Add(nil,'章号');
treeview1.Images:=imagelist1;
treeview1.Items.Item[0].ImageIndex:=0;
adoquery1.First;
while not adoquery1.Eof do
begin
treenode2:=treeview1.Items.AddChild(treenode1,adoquery1.Fields[0].value);
//定义图形
treenode2.ImageIndex:=0;
for i:=0 to adotable1.FieldCount-1 do
begin
fieldname:=adotable1.FieldList.Fields[1].Value;
treenode3:=treeview1.Items.AddChild(treenode2,fieldname);
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from 段 where 章号=:章号');
adoquery2.FieldByName('节号').Value:=adoquery1.Fields[0].Value;//这句一直出现错误, adoquery2.Open;
//在字段明下再分别添加子段数据
while not adoquery2.Eof do
begin
treeview1.Items.AddChild(treenode3,adoquery2.fieldbyname('段号').Value);
treenode3.ImageIndex:=1;
adoquery2.Next;
end;
end;
adoquery1.Next;
end;
end;
用 SQL数据库 怎样在TreeView1 中显示出来,层次为章、节、段