表的内容如下:
POPU_CODE PARENT CONTENT GRADES GRADE PYM
AB ROOT 行政区划 3 1 xzqh
AB11 AB 北京市 3 2 bjs
AB1101 AB11 北京市市辖区 3 3 bjssxq
AB110101 AB1101 北京市东城区 3 4 bjsdcq
AB110102 AB1101 北京市西城区 3 4 bjsxcq
AB110103 AB1101 北京市崇文区 3 4 bjscwq
AB110104 AB1101 北京市宣武区 3 4 bjsxwq
AB110105 AB1101 北京市朝阳区 3 4 bjscyq
如何将其写入treeview控件中
POPU_CODE PARENT CONTENT GRADES GRADE PYM
AB ROOT 行政区划 3 1 xzqh
AB11 AB 北京市 3 2 bjs
AB1101 AB11 北京市市辖区 3 3 bjssxq
AB110101 AB1101 北京市东城区 3 4 bjsdcq
AB110102 AB1101 北京市西城区 3 4 bjsxcq
AB110103 AB1101 北京市崇文区 3 4 bjscwq
AB110104 AB1101 北京市宣武区 3 4 bjsxwq
AB110105 AB1101 北京市朝阳区 3 4 bjscyq
如何将其写入treeview控件中
var
i,j,m,n,m1:integer;
s1,s2:string;
node,subnode:TTreeNode;
begin
form1.Table1.Open;
form1.Table1.First;
i:=form1.Table1.RecordCount;
if i>0 then
begin
for j:=0 to i-1 do
begin
s1:=form1.Table1.FieldValues['parent'];
s2:=form1.Table1.FieldValues['POPU_CODE'];
if s1='root' then
form1.TreeView1.Items.Add(nil,s2)
else
begin
m:=form1.TreeView1.Items.Count;
for n:=0 to m-1 do
begin
if form1.TreeView1.Items.Item[n].Text=s1 then
form1.TreeView1.Items.AddChild(form1.TreeView1.Items.Item[n],s2);
end;
end;
end;
end;
end;
大体思路,没有经过调试
var a:TStrings;
begin a:=TStringList.Create;
while not adodataset1.Recordset.EOF do begin
a.Add(AdodataSet1.Recordset.Fields[0].Value);
adodataset1.Recordset.MoveNext;
end;
a.SaveToFile('d:\aaa.txt');
TreeView1.LoadFromFile('d:\aaa.txt');
a.Free;
end;
adodataset1的commandtext为
select space(grade-1)+content as tvnode from Q order by POPU_CODE