Help needed on filling treeView

  • Thread starter Thread starter tiger79
  • Start date Start date
T

tiger79

Hi,
I've got a sql databse file with some data in it :

ID P_ID Description
1 0 Parent1
2 0 Parent2
3 0 Parent3
4 1 Child1Parent1
5 2 Child1Parent2
6 3 Child1Parent3

Now, i'd like to place all this in a TreeView. Fisrt i'd like to show only
the first level (so that would be parents 1 t 3). When the user clicks on
one of the three nodes i'd like to expand the treeView so that the childs of
the selected node are shown. I managed to get the three parents on screen,
but I cant seems to manage to fill the parents node with its childs during
running time. I think my problem is that I cant find the right commands so
that i can select the appropriate parent and place some chiulds under it.
Any one have any idea how to solve a problem like this, os has some
experience in it ? I can supply my source, cause posting it would be quite
big (becasue of aal the databse reading and stuff)...
Thanx...
 
ok, i managed placing childs under the parents using
treeView1.SelectedNode.Nodes.Add(node);

only problem now is that i have been using the index of the parents to place
the childs, but when the childs are placed under the parents their indexes
start back at 0. For me that means that when i send an sql-query using the
index as part of the sent string it will return wrong values :( again, if
someone has experience i am willing to send my source to look at...
 
Hi,
take a look at using the 'Tag' property of each node, to store your key, or
whatever you need. Then when the node is checked, you can access the tag to
retreive your value

HTH

Pete
 
Jap,
thats exactly what I did afterwards, I even used the Tag to store an object
containing all kinds of info :D
 
Back
Top