N
nydelphi
Unregistered / Unconfirmed
GUEST, unregistred user!
读取数据库来创建Treeview
var
Dep: String;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add('select TreeName from Tree');
open;
First;
while not Eof do
begin
DepNode:=TreeView1.Items.Add(Nil,trim(fieldByName('TreeName').AsString));
with ADOQuery2 do
begin
Dep:=Quotedstr(ADOQuery1.fieldByName('TreeName').AsString);
close;
sql.Clear;
sql.Add('select ChildName from Child where TreeName=' + Dep);
open;
First;
while Not Eof do
begin
TreeView1.Items.AddChild(DepNode,trim(FieldByName('ChildName').AsString));
Next;
end;
end;
Next;
end;
end;
建立父节点
var
sqltext:string;
begin
sqlText := 'Insert into Tree(TreeName) values('''+edit1.Text+''')';
DepNode:=form1.TreeView1.Items.Add(nil,EDIT1.Text);
try
with AdoQuery1 do
begin
close;
sql.Clear;
sql.Add(sqltext);
ExecSQL;
end;
except
end;
end;
现在困惑到创建子节点上面,不知道如何创建了.数据库里面父节点一个表,子节点一个表,
做的是一对一的关系
var
Dep: String;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add('select TreeName from Tree');
open;
First;
while not Eof do
begin
DepNode:=TreeView1.Items.Add(Nil,trim(fieldByName('TreeName').AsString));
with ADOQuery2 do
begin
Dep:=Quotedstr(ADOQuery1.fieldByName('TreeName').AsString);
close;
sql.Clear;
sql.Add('select ChildName from Child where TreeName=' + Dep);
open;
First;
while Not Eof do
begin
TreeView1.Items.AddChild(DepNode,trim(FieldByName('ChildName').AsString));
Next;
end;
end;
Next;
end;
end;
建立父节点
var
sqltext:string;
begin
sqlText := 'Insert into Tree(TreeName) values('''+edit1.Text+''')';
DepNode:=form1.TreeView1.Items.Add(nil,EDIT1.Text);
try
with AdoQuery1 do
begin
close;
sql.Clear;
sql.Add(sqltext);
ExecSQL;
end;
except
end;
end;
现在困惑到创建子节点上面,不知道如何创建了.数据库里面父节点一个表,子节点一个表,
做的是一对一的关系