Results 1 to 3 of 3

Thread: What treeview node was selected

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Question What treeview node was selected

    Still learning vb.net 2005 and was needing to know how to determine what treeview node was selected so I can fire an event. What I have so far is below and it don't work. Each of my nodes have unique names so I can tell them apart pretty easily. Working code examples are best for me since i'm still learning this stuff.


    Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.Click

    'Tc3p1 is the name of the specific node in this case. It's the 2nd child of a parent
    If TreeView1.SelectedNode = Tc3p1 Then

    'Do some stuff here

    End If
    End Sub
    using: VB.Net 2005

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: What treeview node was selected

    Quote Originally Posted by teamdad
    Still learning vb.net 2005 and was needing to know how to determine what treeview node was selected so I can fire an event. What I have so far is below and it don't work. Each of my nodes have unique names so I can tell them apart pretty easily. Working code examples are best for me since i'm still learning this stuff.


    Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.Click

    'Tc3p1 is the name of the specific node in this case. It's the 2nd child of a parent
    If TreeView1.SelectedNode = Tc3p1 Then

    'Do some stuff here

    End If
    End Sub

    I am learning also but I think this is what you are looking for:

    VB Code:
    1. If TreeView1.SelectedNode.Text = "Tc3p1" Then
    2.             'Do some stuff here
    3.  
    4. End If
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Re: What treeview node was selected

    Use the AfterSelect event, which is raised after a node is selected. In the AfterSelect event handler e.Node is the node that was selected.
    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

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