recursive treeview fill - problem
- From: Anwendungsprogrammierer@xxxxxx
- Date: 23 Nov 2006 12:07:27 -0800
Hello newsgroup,
i got a table with this layout:
id__ name parent_id__
it stores data to recursively fill a treeview.
Now I wrote a function like that to fill the tree, but it does not seem
to work right, it adds one empty item below every node. I cant find the
flaw - pls help.
first call is filltree(nil,'')
procedure TMain.FillTree(N : TTreeNode; Parent : String);
var x, rsC : _recordset;
TreeParent, treechild : TTreeNode;
cmd : string;
begin
With self.navTree.Items do
begin
if n =nil then begin
// clear nodes
clear;
cmd:='SELECT id__,name, parent_id__ FROM tbl_Entries WHERE
parent_id__ is NULL';
x:=dblayer.Execute(cmd);
while not x.EOF do begin
application.ProcessMessages;
if x.Fields.Item[2].Value = null then begin
treeparent:=add(nil,x.Fields.Item[1].Value);
cmd:='SELECT id__,name, parent_id__ FROM tbl_Entries WHERE
parent_id__ =''' + x.Fields.Item[0].Value + '''';
rsc:=dblayer.Execute(cmd);
while not rsc.EOF do begin
if rsc.Fields[2].Value ='' then
application.ProcessMessages
else begin
showmessage(rsc.Fields.Item[0].value +
':'+rsc.Fields.Item[1].value);
TreeChild :=
AddChild(TreeParent,rsc.Fields.Item[1].value);
FillTree(TreeChild,rsc.Fields.item[0].value);
end;
if not rsc.EOF then rsc.MoveNext;
end;
end;
if not x.EOF then x.movenext;
end;
end
else begin
if parent='' then exit;
cmd:='SELECT id__,name, parent_id__ FROM tbl_Entries WHERE
parent_id__ =''' + parent + '''';
rsc:=dblayer.Execute(cmd);
repeat
TreeChild := AddChild(n,rsc.Fields.Item[1].value);
FillTree(TreeChild,rsc.Fields.Item[0].Value);
if not rsc.EOF then rsc.movenext;
until rsc.EOF
end;
end;
end;
.
- Follow-Ups:
- Re: recursive treeview fill - problem
- From: Rob Kennedy
- Re: recursive treeview fill - problem
- Prev by Date: Simulating a menu click
- Next by Date: DBGrid scroll bars
- Previous by thread: Simulating a menu click
- Next by thread: Re: recursive treeview fill - problem
- Index(es):