Results 1 to 11 of 11

Thread: Combo Box Adding

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  2. #2

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Combo Box Adding

    I have this and it is not working:

    VB Code:
    1. Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    2.     Dim i As Integer
    3.     Dim bFound As Boolean
    4.     Me.Caption = brwWebBrowser.LocationName & " - RapidFriends Explorer"
    5.     If cmbAddress <> cmbAddress.Text Then
    6.         For i = 0 To cmbAddress.ListCount - 1
    7.             If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
    8.                 bFound = True
    9.                 Exit For
    10.             End If
    11.         Next i
    12.     End If
    13.     mbDontNavigateNow = True
    14.     If bFound Then
    15.         cmbAddress.RemoveItem i
    16.     End If
    17.     Dim strSomeValue
    18.     lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, strSomeValue)
    19.     If lngRetVal > -1& Then
    20.         ' Do nothing
    21.     Else
    22.         cmbAddress.AddItem brwWebBrowser.LocationURL, 0
    23.         cmbAddress.ListIndex = 0
    24.     End If
    25.     stbBrowser.Panels(1).Text = "Done!"
    26.     mbDontNavigateNow = False
    27. End Sub
    My usual boring signature: Something

  4. #4

  5. #5

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Combo Box Adding

    i was just using Martin's code
    My usual boring signature: Something

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Combo Box Adding

    I think what Rhino was trying to ask is what purpose does this code serve?

    VB Code:
    1. If cmbAddress <> cmbAddress.Text Then
    2.         For i = 0 To cmbAddress.ListCount - 1
    3.             If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
    4.                 bFound = True
    5.                 Exit For
    6.             End If
    7.         Next i
    8.     End If

  8. #8

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  9. #9
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Combo Box Adding

    Quote 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:
    1. Option Explicit
    2. Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _
    3.                       (ByVal hWnd As Long, _
    4.                        ByVal wMsg As Long, _
    5.                        ByVal wParam As Long, _
    6.                        ByVal lParam As String) As Long
    7. Private Const LB_FINDSTRINGEXACT = &H1A2
    8. Private Const CB_FINDSTRINGEXACT = &H158
    9. Private Const CB_FINDSTRING = &H14C
    10. Private Const LB_FINDSTRING = &H18F
    11.  
    12. Private Sub Combo1_KeyPress(KeyAscii As Integer)
    13.    
    14.     If KeyAscii = 13 Then
    15.         Dim lngRetVal As Long
    16.         lngRetVal = SendMessageString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1&, Combo1.Text)
    17.    
    18.         If lngRetVal = -1& Then _
    19.             Combo1.AddItem Combo1.Text
    20.     End If
    21. End Sub
    Show Appreciation. Rate Posts.

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    2.    
    3.     Dim lngRetVal As Long
    4.     lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, CStr(URL))
    5.     If lngRetVal > -1& Then
    6.         ' The url is already in cmbAddress so don't add it again
    7.     Else
    8.         cmbAddress.AddItem CStr(URL)
    9.         cmbAddress.ListIndex = 0
    10.     End If
    11.    
    12. End Sub

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Combo Box Adding

    Quote Originally Posted by MartinLiss
    I think what Rhino was trying to ask is what purpose does this code serve?

    VB Code:
    1. If cmbAddress <> cmbAddress.Text Then
    2.         For i = 0 To cmbAddress.ListCount - 1
    3.             If cmbAddress.List(i) = brwWebBrowser.LocationURL Then
    4.                 bFound = True
    5.                 Exit For
    6.             End If
    7.         Next i
    8.     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
  •  



Click Here to Expand Forum to Full Width