[RESOLVED] How to get node index of treeview branch
After searching most of the treeview node posts I have not been able to find the answer I am looking for.
I have a treeview loaded like the following example:
Parent1
Child1
GrandChild1
GreatGrandChild1
GreatGrandChild2
GreatGrandChild3
GrandChild2
GreatGrandChild1
GreatGrandChild2
Child2
GrandChild1
GreaGrandChild1
Parent2
Child1
GrandChild1
GreatGrandChild1
GreatGrandChild2
GreatGrandChild3
GrandChild2
GreatGrandChild1
GreatGrandChild2
Child2
GrandChild1
GreaGrandChild1
When I select a node I need to display data from a database>table> record specific to that node.
The database has four tables. Parent, Child, GrandChild and GreatGrandChild.
Each record in the Parent table has the following fields:
ParentNodeIdx, ParentData
Each record in the Child table has the following fields:
ParentNodeIdx, ChildNodeIdx, ChildData
Each record in the GrandChild table has the following fields:
ParentNodeIdx, ChildNodeIdx, GrandChildNodeIdx, GrandChildData
Each record in the GreatGrandChild table has the following fields:
ParentNodeIdx, ChildNodeIdx, GrandChildNodeIdx, GreatGrandChildNodeIdx, GreatGrandChildData
My problem is trying to figure out what the node indexes are for the Parent and Child Nodes when I mouse click on the GreatGrandChild node. I use the Treeview1.SelectedNode.Index to get the GreatGrandChildNode Index and the Treeview1.SelectededNode.Parent.Index to get the GrandChildnode index but can't figure out how to get the Child and Parent Node indexes.
Sorry for the long post but I tried to make my problem as clear as I could.
Thanks for any and all suggestions
Richard
Re: How to get node index of treeview branch
Each TreeNode object has a Tag property, so you can store arbitrary information there. When the user selects a node, you can get its Tag data and then get the next node up the chain from its Parent property. Keep doing that up the chain until the Parent is Nothing and you know that you're at the top level.
You could even define your own class(es) derived from TreeNode and add your own properties to store your own data.
Re: How to get node index of treeview branch
This article talks about extending the TreeNode class like hmcilhinney suggested: How to create a Key property for a TreeView node in Visual Basic.
Re: How to get node index of treeview branch
I'll try the Tags idea and see if I can make that work. Thanks for both replies.
Richard
Re: How to get node index of treeview branch
The Tags idea solved my problems. Thanks again!