|
-
May 21st, 2013, 09:30 AM
#1
Thread Starter
Member
[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
-
May 21st, 2013, 09:48 AM
#2
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.
-
May 21st, 2013, 09:55 AM
#3
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.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
May 21st, 2013, 09:59 AM
#4
Thread Starter
Member
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
-
May 22nd, 2013, 03:27 PM
#5
Thread Starter
Member
Re: How to get node index of treeview branch
The Tags idea solved my problems. Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|