|
-
Sep 11th, 2006, 05:32 PM
#1
Thread Starter
WiggleWiggle
Combo Box Adding
I am creating a webbrowser and when the user enter a webpage into the address bar (combo box) it adds it to it for later reference.
I want it so that it does not add it again, if it is already there. How do i do this? thanks in advanced
My usual boring signature: Something
-
Sep 11th, 2006, 05:45 PM
#2
Re: Combo Box Adding
See my post#4 in this thread.
-
Sep 11th, 2006, 08:43 PM
#3
Thread Starter
WiggleWiggle
Re: Combo Box Adding
I have this and it is not working:
VB Code:
Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Dim i As Integer
Dim bFound As Boolean
Me.Caption = brwWebBrowser.LocationName & " - RapidFriends Explorer"
If cmbAddress <> cmbAddress.Text Then
For i = 0 To cmbAddress.ListCount - 1
If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
bFound = True
Exit For
End If
Next i
End If
mbDontNavigateNow = True
If bFound Then
cmbAddress.RemoveItem i
End If
Dim strSomeValue
lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, strSomeValue)
If lngRetVal > -1& Then
' Do nothing
Else
cmbAddress.AddItem brwWebBrowser.LocationURL, 0
cmbAddress.ListIndex = 0
End If
stbBrowser.Panels(1).Text = "Done!"
mbDontNavigateNow = False
End Sub
My usual boring signature: Something
-
Sep 11th, 2006, 08:49 PM
#4
Re: Combo Box Adding
strSomeValue should be replaced by the string or value you are looking for.
-
Sep 11th, 2006, 08:57 PM
#5
Re: Combo Box Adding
I'm not convinced about the purpose of having loop and SendMessage all together - one or the other I guess...
-
Sep 11th, 2006, 09:44 PM
#6
Thread Starter
WiggleWiggle
Re: Combo Box Adding
i was just using Martin's code
My usual boring signature: Something
-
Sep 11th, 2006, 09:45 PM
#7
Re: Combo Box Adding
I think what Rhino was trying to ask is what purpose does this code serve?
VB Code:
If cmbAddress <> cmbAddress.Text Then
For i = 0 To cmbAddress.ListCount - 1
If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
bFound = True
Exit For
End If
Next i
End If
-
Sep 11th, 2006, 10:23 PM
#8
Thread Starter
WiggleWiggle
Re: Combo Box Adding
I am confused. What do i need to put in the code, so that it will not add the url to the combobox, if it is already there?
My usual boring signature: Something
-
Sep 12th, 2006, 03:36 AM
#9
Re: Combo Box Adding
 Originally Posted by dclamp
I am confused. What do i need to put in the code, so that it will not add the url to the combobox, if it is already there?
There is no need for that loop. Using Martin's code, instead of using a command button's event, use the Combo's Keypress event:
VB Code:
Option Explicit
Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Const CB_FINDSTRINGEXACT = &H158
Private Const CB_FINDSTRING = &H14C
Private Const LB_FINDSTRING = &H18F
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim lngRetVal As Long
lngRetVal = SendMessageString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1&, Combo1.Text)
If lngRetVal = -1& Then _
Combo1.AddItem Combo1.Text
End If
End Sub
-
Sep 12th, 2006, 07:19 AM
#10
Re: Combo Box Adding
I don't understand how the navigate sub works but I assume that URL is the url that you navigated to. If that is true then the following is all you need.
VB Code:
Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Dim lngRetVal As Long
lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, CStr(URL))
If lngRetVal > -1& Then
' The url is already in cmbAddress so don't add it again
Else
cmbAddress.AddItem CStr(URL)
cmbAddress.ListIndex = 0
End If
End Sub
-
Sep 12th, 2006, 08:01 AM
#11
Re: Combo Box Adding
 Originally Posted by MartinLiss
I think what Rhino was trying to ask is what purpose does this code serve?
VB Code:
If cmbAddress <> cmbAddress.Text Then
For i = 0 To cmbAddress.ListCount - 1
If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
bFound = True
Exit For
End If
Next i
End If
Exactly Martin.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|