Results 1 to 1 of 1

Thread: Replacing ComboBox With ImageCombo!

Threaded View

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Replacing ComboBox With ImageCombo!

    In a WebBrowser project, I want to add those URLs in the address bar ImageCombo which the user types. Such URLs are saved in a text file so that they can be populated in the address bar when the browser starts next time. Also it has to be ensured that URLs that are already listed in the address bar shouldn't get listed again i.e. there shouldn't be any duplicates. This is how I tried it:
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    2.  
    3. 'the [b]ImageCombo[/b] has an index of 0
    4. Private Sub [b]imgCboURL_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)[/b]
    5.     If (KeyCode = vbKeyReturn) Then
    6.         '[u]Call cboURL_Click(0)[/u]
    7.         Call imgCboURL_Click(0)
    8.     End If
    9. End Sub
    10. Private Sub [b]imgCboURL_Click(Index As Integer)[/b]
    11.     '[u]Call AddToCombo(cboURL(0).Text, cboURL(0))[/u]
    12.     Call AddToCombo(imgCboURL(0).Text, imgCboURL(0))
    13. End Sub
    14. '[u]Private Sub AddToCombo(pstrComboItem As String, pCB As ComboBox)[/u]
    15. Private Sub [b]AddToCombo(pstrComboItem As String, pCB As ImageCombo)[/b]
    16.     On Error Resume Next
    17.     Dim lngComboIndex As Long
    18.     Dim objNewComboItem As ComboItem
    19.    
    20.     If (InStr(pstrComboItem, "http://") = 0) Then
    21.         'if the user hasn't typed http:// in the address bar, append it
    22.         pstrComboItem = "http://" & pstrComboItem
    23.     Else
    24.         'else leave the URL as it is
    25.         pstrComboItem = pstrComboItem
    26.     End If
    27.     lngComboIndex = SendMessage(pCB.hwnd, CB_FINDSTRING, -1, ByVal pstrComboItem)
    28.     If (lngComboIndex = -1) Then
    29.         Set objNewComboItem = pCB.ComboItems.Add(1, , pstrComboItem, 2)
    30.         [u]'pCB.AddItem pstrComboItem[/u]
    31.         Dim iFile As Integer
    32.         Dim FileName As String
    33.        
    34.         iFile = FreeFile
    35.         FileName = App.Path & "\TypedURLs.txt"
    36.         Open FileName For Append As #iFile
    37.             Write #iFile, pstrComboItem
    38.         Close #iFile
    39.     End If
    40. End Sub
    Earlier I was using a ComboBox as the address bar. The changes I have made to the above-mentioned code when I replaced the ComboBox with the ImageCombo are the underlined commented lines (of course, plus the code to populate the ImageCombo).

    The problem is the above code worked perfectly when I was using the ComboBox but the same isn't happening when I changed to the ImageCombo. Using the ImageCombo, URLs that are already listed in the ImageCombo address bar are getting listed again & again if such a URL is typed again by the user. I didn't face this problem when I was using the ComboBox.

    Can someone please point out where am I erring?
    Last edited by arpan_de; Jan 3rd, 2006 at 11:11 AM.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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