blowfelt Posted October 20, 2003 Posted October 20, 2003 hello, i'm trying to implement a treeview control populated by hierarchial data returned from a database. i have a parent child and name structure returned from a select statement into a data reader record set. i can see that there are no longer parent/child properties of the node objects (i used to use vb6). how can i code this? when i've tried to iterate through the nodes to find a specific value in order to add children, the nodes only itterate the imediate child level? arrrrgggggg:( thanks Quote
*Experts* Volte Posted October 20, 2003 *Experts* Posted October 20, 2003 Each Node has its own Node collection. To add a node, just add to the Node's Nodes collection. And yes, there is indeed a Parent property of the TreeNode object to tell you which node it is a child of. Quote
blowfelt Posted October 20, 2003 Author Posted October 20, 2003 cheers simon, but how do i get back to a specific node to add more children? like i said, when i try to itterate through the nodes i can only check the top level? Quote
*Experts* Volte Posted October 20, 2003 *Experts* Posted October 20, 2003 Well, you would store the node when you add it. Like this:Dim n As New Node n.Text = "This is the top node!" n.Nodes.Add("This is a child of that node!") Dim nc As Node = n.Nodes.Add("This is a second child!") nc.Nodes.Add("This is a child of a child!") tree.Nodes.Add(n)Try that. Quote
blowfelt Posted October 20, 2003 Author Posted October 20, 2003 cheers simon, i understand the code you've supplied, but that assumes you know how many parent levels/nodes are needed... i need to implement the code in a loop that can call up previous nodes and add to them... i think i may be missing a trick??? Quote
*Experts* Volte Posted October 20, 2003 *Experts* Posted October 20, 2003 I don't know what you need.... as long as you store the parent node in a variable (or find it by iterating through recursively through the TreeView's Nodes collection), you can add children to it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.