In a web browser app, I am using a TreeView to display the history of the pages visited by a user. The Text of the nodes in the TreeView is the title of the web page & it's corresponding URL is set as the Tag of the node.
When a node in the TreeView is right-clicked, a menu appears. Clicking a menu item named Properties opens a new Form which displays the title & the URL of the web page (node) that is selected. The title of the selected web page (node) is displayed in a read-only TextBox named txtTitle & the URL is displayed in a read-only TextBox named txtURL. This is how I have tried it (note that the TreeView can also be closed - the code of which is not shown here):
When only one browser window is open, any web page right-clicked in the TreeView displays the corresponding title & URL correctly. The problem comes up when more than one browser window is open.Code:Sub ReadPageDetails() Dim frm As Form Dim strURL As String Dim strTitle As String Dim i As Integer 'looping through the Forms collection since more than one browser window can be open at any given time For Each frm In Forms If (frm.Name = "frmWebBrowser") Then If (frm.tvwHistory.Visible = True) Then For i = 1 To frm.tvwHistory.Nodes.Count If (frm.tvwHistory.Nodes(i).Selected = True) Then strTitle = frm.tvwHistory.Nodes(i).Text strURL = frm.tvwHistory.Nodes(i).Tag txtTitle.Text = strTitle txtURL.Text = strURL End If Next End If End If Next End Sub
Assume that 2 browser windows are open. In the 2nd window, the user opens the TreeView to view his history. Suppose he right-clicks the web page Google & selects Properties. The new Form opens up & displays the correct title (Google in txtTitle) & URL (http://www.google.com in txtURL).
Keeping the TreeView in the 2nd browser window visible/open, the user goes back to the 1st browser window & opens the TreeView to view his history. Now suppose he right-clicks the web page Yahoo & selects Properties. The Properties Form opens up but it displays the wrong title & URL. The Properties Form in the 1st browser window still displays the title as Google (in txtTitle) & URL as http://www.google.com (in txtURL) whereas it should have displayed the title as Yahoo (in txtTitle) & URL as http://www.yahoo.com (in txtURL) i.e. the Properties Form in the 1st browser window displays the details of the web page that has been selected in the TreeView of the 2nd browser window.
This happens because the TreeView in the 2nd browser window is still open. If the TreeView in the 2nd browser window is closed & the user right-clicks Yahoo in the TreeView of the 1st browser window & selects Properties, this time the Properties Form correctly displays the title as Yahoo (in txtTitle) & URL as http://www.yahoo.com (in txtURL).
Now how do I ensure that irrespective of the no. of browser windows that are open & irrespective of whether the TreeView in each browser window is open or not, the Properties Form displays the correct title & URL?




ARPAN
Reply With Quote