Treeview and webBrowser

dualshock03

Well-known member
Joined
Jan 28, 2007
Messages
105
Programming Experience
1-3
How can i link a node and a subnode to a web browser control? i have a treeview control as a navigation panel and a webBrowser control. i want every node have a click event that opens a web page to the webBrowser control.. how to do it?
 
You use the AfterSelect event of Treeview control, treenode is given by event parameter 'e.Node'. This is the default event of the TreeView control, which means this is the event handler that is inserted in code when you doubleclick the control in Designer view.

To navigate the WebBrowser control you use its Navigate method.
 
VB.NET:
    Sub setupTreeview()
        TreeView1.Nodes.Add("www.vbdotnetforums.com")
    End Sub
   
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) _
    Handles TreeView1.AfterSelect
        WebBrowser1.Navigate(e.Node.Text)
    End Sub
 
Hi John i got some new problem to this.. I already tried to follow your sample and made to run the application well, but encountering some double execution of events to the tree nodes..

Here's my code:
VB.NET:
[COLOR=Blue]Private Sub [/COLOR][COLOR=Green]NoderootA[/COLOR]_NodeMouseClick([COLOR=Blue] Byval [COLOR=Black]sender[/COLOR][/COLOR][COLOR=Blue]as[/COLOR] object....

WebBrowser2.Hide()
WebBrowser1.Show()             
WebBrowser1.Navigate([COLOR=DarkRed]"C:\Documents and Settings\amastud\Desktop\New Folder\interest.html"[/COLOR])

[COLOR=Blue]End Sub[/COLOR]
-------------------------------------------------------------------------

[COLOR=Blue]Private Sub [/COLOR]NodechildA_NodeMouseDoubleClick([COLOR=Blue]Byval[/COLOR] sender [COLOR=Blue]as [/COLOR]object....

WebBrowser1.Hide()
WebBrowser2.Show()
WebBrowser2.Navigate([COLOR=DarkRed]"C:\Documents and Settings\amastud\Desktop\New Folder\midterm.html"[/COLOR])

[COLOR=Blue]End Sub[/COLOR]
-------------------------------------------------------------------------
The URL navigation works for NoderootA, but every time i doubleClick the NoderootA, NodechildA 's URL page appears too at webBrowser1! which supposed to be functioning at webBrower2... and when im singleclicking NodechildA, NoderootA URL page appears at webBrowser2..else doubleclicking at NodechildA seems normal.:confused:



Hope you can answer my confusing question..

Regards!!
...Later im going to attach my app here for your clarification:)


 
Use the AfterSelect event of TreeView control instead and differenciate the root/child with e.Node.Level
 
Back
Top