Treeview with DB problem D7/ADO

2005-05-07 11:49:18 AM
Hi all!
Not sure if this is the right forum for this question
I'm busy creating a family tree app and has run into a problem. After retrieving parent and child information from database, I tried to add them in a treeview by looping through the database results. To explain further, my tables have only two parent info in them, with one set of parents having more than one child, but when i add the results to the treeview, each parent name is retrieved and displayed(with children) according to the number of children they have. For example:
if you have parent1 with 2 children AND parent2 with 3 children
then name of parent1 will be displayed twice, with one of the children's names each and likewise with parent2. Whilst the correct way it should display this info is: parent1 with two children and parent2 with 3 children.
Here's the code i use to retrieve and display the info:
procedure TForm1.Button1Click(Sender: TObject);
q1.SQL.Text:='select [],[] from [child],[person] where []=[]';
while not q1.EOF do
with tv_eg1.Items.AddFirst(nil, 'Parents - ' + q1.fieldbyname('').Text ) do
{Select the root node}
Selected := true;
tv_eg1.Items.AddChild( tv_eg1.Selected, 'Child - ' + q1.fieldbyname('').Text );
I hope this makes sense!