|
-
Sep 26th, 2011, 08:21 PM
#1
Thread Starter
Lively Member
[RESOLVED] How to determine which Child Node of a treeview has been clicked
Hi all
Right now I have a treeview with 2 parent nodes and each Parent Node has multiple child nodes.
I would like to display the text of the Child Node in a textbox. Which I have been unsuccessful.
The code I'm displaying below shows both parent and child node. But I only want the child node.
Thank you
Code:
Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
MsgBox(e.Node.Text)
End Sub
-
Sep 26th, 2011, 08:29 PM
#2
Re: How to determine which Child Node of a treeview has been clicked
I'm confused. Is this a question or an answer? If it's a question then it doesn't make sense because the code posted doesn't do what you say it does.
If it's an answer then why is it here and not in the thread the question was posted in? Also, if it's an answer then it's one likely to confuse because you have a method named TreeView1_NodeMouseDoubleClick handling the TreeView1.NodeMouseClick event.
-
Sep 26th, 2011, 08:39 PM
#3
Thread Starter
Lively Member
Re: How to determine which Child Node of a treeview has been clicked
Sorry jmcilhinney if the question is confusing.
I'm a Nobie.
What I'm trying to do is know the text of the child node when it is clicked.
I need this so I can search the DataBase with the name of the childnode.
I could do this using two listviews. But I would like to use the treeview instead.
Thanks for your quick reply
-
Sep 26th, 2011, 08:47 PM
#4
Re: How to determine which Child Node of a treeview has been clicked
May I recommend that, in future, you don't put your own words in a Quote box? The point of the Quote box is to indicate that you are quoting someone else's words, normally from an earlier post.
I think I see what you're saying now. I though you meant that, when you clicked a child node, it was displaying the text from the parent node and the child node. Now I'm thinking that you mean that when you click a parent node you see the text of the parent node and when you click the child node you see the text of the child node, which is what you'd expect, but you actually don't want to see anything when you click a parent node, only a child node. Is that correct?
Assuming that is correct, what you obviously need to do is to check whether the node is a parent or a child first, then only display the text if it's a child. So, how do you know whether a node is a parent or child? Have you thought about that? Have you read the documentation for the TreeNode class? Not surprisingly, it tells you how a TreeNode works so it would be the place to learn about that.
Also, as I pointed out, your code is bad because your are handling an event with a method indicates that it handles some other event. Apart from that, you might be better off handling AfterSelect rather than NodeMouseClick. What if the user selects a node using the keyboard?
-
Sep 26th, 2011, 08:55 PM
#5
Thread Starter
Lively Member
Re: How to determine which Child Node of a treeview has been clicked
thnks jmcilhinney
I will check the treeview class again until I find what I want.
In the future I will not Post my question in Quote.
-
Sep 26th, 2011, 09:02 PM
#6
Re: [RESOLVED] How to determine which Child Node of a treeview has been clicked
 Originally Posted by viper5646
I will check the treeview class again until I find what I want.
That won't do you much good. Perhaps you'd be better off doing what I actually suggested.
 Originally Posted by jmcilhinney
Have you read the documentation for the TreeNode class?
It's the node itself you're interested in, so that's what you need to look at.
Do you like how I demonstrated correct use of the Quote box there?
Tags for this Thread
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
|