how to select child node in Treeview

Lek

New member
Joined
Aug 2, 2008
Messages
4
Programming Experience
Beginner
Let say i was created a treeview and that include some parent nodes.Each parent nodes also include some child nodes.So , i want when me double click the treeview component (Private sub..... Handles tv.DoubleClick).It will do something but the problem how i define which child node i selected?

Example :

IF e.node.index = 1 Then

do something

End If

but the e.node.index is getting the parent selected node index only ..how to get the child selected node index when i choose child node...:confused:
 
The node selected is e.Node, the Node.Index property refer to the index in the Nodes collection the node belongs to.
 
no ..
eg:
+Index 1 : A (parent node)
- Index 1 :A1 (child node)
- Index 2 :A2 (child node)
+Index 2 : B (Parent node)

when i want double click on A1(child node) , then will do something ,,, but impossible my e.node = 1 de? The IDE will define parent node is selected.
 
Last edited:
Except indexes start at 0 your list is correct, so what is the problem?? Trying to explain what you are doing and want to achieve may be a better approach if you need help. You said on mouse event "do something", what is it you want to do? You have the node provided by e.Node.
 
wat i want is when i double click my child node (A1) ,,then can do something.

e.g : Private sub tv_db(.......) handles Mouse.DoubleClick

If e.node = 1 Then

<- because the Parent Node A and child node A1 also same index number ,so how? ->

End if

i want double the child node to execute smth in my app.what better suggesstion to me about it ?
 
You have the node (e.Node), what else do you need??

Btw, the nodes may have same index number, but it is not the same index since they belong to different treenode collections. Get over it, it is the way it is.
 
Like John H says, the
VB.NET:
 e.node
or the [e.node.Tag] or the [e.node.Text] can be used

e.g. I use the e.node.Tag for doing specific actions like loading employee records from a form(or more like a subform) into a panel on my parent form that also has the tree.

If what John H mentioned doesnt help, try rephrasing your question. I'm also working with the tree control now and the e.node is the real trick to most "which node have i clicked and what should happen " problem


Question: Have you set the tag properties for each node in the section of your code for the tree control...

e.g.
VB.NET:
Dim childrow As DataRow
                Dim childnode As TreeNode
                childnode = New TreeNode()
                For Each childrow In parentrow.GetChildRows("DeptToJob")
                    childnode = parentnode.Nodes.Add(childrow(0) & " " & childrow(1) & " " & childrow(2))
                    childnode.Tag = childrow("dept_id")

then I can use the
VB.NET:
e.node.tag
to return a value to a form or a text box or a listbox

e.g. under the
VB.NET:
treeView1_afterSelect
I can use an
VB.NET:
textbox1.text = e.node.tag
something like that..

hope this helps
 
Last edited:
thx daPoet..

i got think ur suggestion be4 .but i hope can get a more better solution to solve it .
actually , use tag oso nt bad ! i hope tat work! :)
 
Back
Top