Browser New Window Problems
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):
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
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.
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?
Re: Browser New Window Problems
Someone please help me out with this....please
Re: Browser New Window Problems
Please do not bump threads. I have deleted your last post.
Re: Browser New Window Problems
Could you please clarify what does "bump threads" mean? Repeating the same question?
Re: Browser New Window Problems
No, but we don't like that either!
Bumping threads is replying with something like "somebody answer" or similar (like you did in post #2).. which is not actually giving us any new information, and so it seems that you are not making any effort to solve it yourself.
We are here to help, not do all of the work for you - and bumping makes it look as if you are expecting us to do everything. It is much better to try to solve it yourself, and tell us what you have achieved, along with an updated question if appropriate.
Re: Browser New Window Problems
That's right.....I very much agree with you but I did try it myself otherwise I wouldn't have posted what I tried in post #1. What I can't comprehend is, assuming that more than 1 browser window is open & the TreeView in all the windows is open, how do I associate a TreeView with that browser window only to which it belongs to (or in which it is open).
Re: Browser New Window Problems
When the user clicks the Properties menu item, which I am assuming Loads/Shows the Properties Form, you know exactly which Node the clicked upon. Why not just pass that Node object to the Properties Form, basically telling it to "show the data from this node"?
Or better yet, create Title and URL properties on the Properties Form whose values can be set by any process wishing to show the form.
Or even just set the textbox values on the form directly.
Pretty basic stuff.
Re: Browser New Window Problems
Pretty basic stuff.....even I thought so.....
Quote:
Why not just pass that Node object to the Properties Form, basically telling it to "show the data from this node"?
That's what I am doing. If a node is selected, I am retrieving that node's Text & Tag properties using
Code:
strTitle = frm.tvwHistory.Nodes(i).Text
strURL = frm.tvwHistory.Nodes(i).Tag
but it's not working. If the TreeView of the 1st browser window is closed, then the Properties Form in the 2nd browser window shows the correct title & URL of the node that is selected in the TreeView of the 2nd browser window but if the TreeView in the 1st browser window is visible, then the Properties Form shows the incorrect title & URL of the node that is selected in the TreeView of the 2nd browser window. Under such circumstances, the Properties Form in the 2nd browser window shows the title & URL of the node that is selected in the TreeView of the 1st browser window.
Re: Browser New Window Problems
You are not "passing" the node object to the Properties Form. The code is trying to "Find" a node but it assumes only one treeview is open at a time (as you know).
Code:
'in the Properties Form
Public Sub ReadPageDetails(Node As MSComctlLib.Node)
txtTitle.Text = Node.Text
txtURL.Text = Node.Tag
Show
End Sub
' in the form with the treeview
'call the method from the popupmenu's click event
Private Sub mnuProperties_Click()
If Not tvwHistory.SelectedItem Is Nothing Then
Call frmProperties.ReadPageDetails(tvwHistory.SelectedItem)
End If
End Sub
Re: Browser New Window Problems
But what code do I add in mnuProperties_Click() to display the Properties Form?
Earlier I was doing it like this:
Code:
'Form with TreeView
Private Sub mnuProperties_Click()
Dim frm As frmPageProperties
Set frm = New frmPageProperties
Call frm.ShowMe(Me)
End Sub
'Properties Form
Public Sub ShowMe(OwnerForm As Form)
Set frmOwner = OwnerForm
Me.Show vbModeless, frmOwner
frmOwner.Enabled = False
End Sub