basic use of treeview

I am very new to VB.net and programming in general so any assistance is much appreciated

I have added a treeview control to a form and have added nodes within that but after much googling have not yet found how to respond to someone choosing a child node.

My project consists of 1 form with a treeview and a webbrowser control, i would like someone to be able to click on a child node and that cause the webbrowser to go to a specified webpage.

I will continue my quest on google but if any one would be kind enough to show me how i do this and break down the code for me to understand I would be very gratefull

Many Thanks

Polstar



Answer this question

basic use of treeview

  • Chris Olson

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
      ' Determine by checking the Node property of the TreeViewEventArgs.
      MessageBox.Show(e.Node.Text)
    End Sub
    
    This is an MSDN sample. It shows the text of the node in a message box, 
    but you can interact with the node any way you like.
     


  • John Petritis

    Many Thanks Christian

    I dont really understand the start of the code but I have modified the action carried out after the users choice has been identified.

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    Dim chosen As String = e.Node.Text
    Dim URL As String
    If chosen = "option1" Then URL = "
    www.example1.com"
    If chosen = "option2" Then URL = "
    www.example2.com"
    WebBrowser1.Navigate(URL)
    End Sub

    I tried using select and case but got a little lost so i will investigate them next to clean the code up.

    Polstar


  • basic use of treeview