Results 1 to 6 of 6

Thread: [RESOLVED] How to determine which Child Node of a treeview has been clicked

  1. #1

    Thread Starter
    Lively Member viper5646's Avatar
    Join Date
    Feb 2009
    Location
    kitchener Ontario
    Posts
    90

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member viper5646's Avatar
    Join Date
    Feb 2009
    Location
    kitchener Ontario
    Posts
    90

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member viper5646's Avatar
    Join Date
    Feb 2009
    Location
    kitchener Ontario
    Posts
    90

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] How to determine which Child Node of a treeview has been clicked

    Quote Originally Posted by viper5646 View Post
    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.
    Quote Originally Posted by jmcilhinney View Post
    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Click Here to Expand Forum to Full Width