Results 1 to 14 of 14

Thread: Finding list item as u typed in combo box(Dropdown List style).

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Basically the title say it all.

    When I type a letter in combo box it finds item by matching the letter that I typed, but when I type in a second letter it searchs item that starts with the second letter.

    I wonder is there a way to macthing list item as u typed in combo box(Dropdown List style).

    Thanks in advance.
    Joon



  2. #2
    Junior Member
    Join Date
    Nov 1999
    Location
    Sydney, NSW, Australia
    Posts
    16

    Post

    I am using a Combo Box in an application with the Style property set to 1. This is a simple Combo Box, not a drop down.

    This means it takes more screen real estate, but I have it on o pop up window and it works fine.


  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Read the Previous Post


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  4. #4

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Serge, it's not work for dropdown list combo box.

    I tried ur code for change events, which won't trigger when I type in combobox, and keydown events, but it didn't work.

    It's not a big deal, but would be nice if I can use that feature

    Thanks
    Joon

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Jpark...

    try this post http://www.vb-world.net/ubb/Forum1/HTML/010330.html

    [This message has been edited by David Laplante (edited 11-16-1999).]

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Thanks David,

    But I tried that already.

    It probably works fine with combo box style-0(Dropdown Combo), but doesn't work with style-2(Dropdown list).

    I get run-time error '380', which is Invalid property value for Combo1.SelStart.

    Joon

  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this:
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const CB_FINDSTRING = &H14C
    
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        Static sTyped As String
        Dim iIndex As Integer
        sTyped = sTyped & Chr(KeyAscii)
        iIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, 0, ByVal sTyped)
        If iIndex > -1 And KeyAscii <> vbKeyDelete And KeyCode <> vbKeyBack Then
            Combo1 = Combo1.List(iIndex)
        Else
            sTyped = ""
            KeyAscii = 0
        End If
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Hi Aaron,

    I don't get any error from ur code, but still dosen't work the way I wanted to be.

    It only matches first character of item list.
    If I type "VS" it finds item that starts with letter "V" then finds item that starts with "S" ignoring letter "V".

    I want to find items that has "VS", when I type "VS".

    Thanks for replies.
    Joon

  9. #9
    Junior Member
    Join Date
    Nov 1999
    Location
    Thailand
    Posts
    20

    Post

    Try This Procedure. I used it in my project.
    It's really work.
    Sub Gs_ComboPress(cboCombo As Control, vKeyAscii)
    '=================================================
    'Function : Use show value of combo (deafault) when press any key.(Ascii)
    'Comment : Use procedure at event "keypress"
    '=================================================
    Dim cboComboTxt As String, xlen%, i%
    cboCombo.SelText = ""
    cboComboTxt = cboCombo.Text & Chr(vKeyAscii)
    xlen = Len(cboComboTxt)
    For i = 0 To cboCombo.ListCount - 1
    If Len(cboCombo.List(i)) >= xlen Then
    If UCase(Left(cboCombo.List(i), xlen)) = UCase(cboComboTxt) Then
    cboCombo.Text = cboCombo.List(i)
    cboCombo.SelStart = xlen
    cboCombo.SelLength = Len(cboCombo.List(i)) - xlen
    Exit For
    End If
    End If
    Next
    If vKeyAscii >= 45 Then
    vKeyAscii = 0
    End If
    End Sub

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Hi pavinda,

    I'm using combo box style-2(Dropdown List), which accept only text that are already in the combo list, and I don't think u can set the SelStart property to certain number in this style of combo box

    To make combo box be empty,I have to do like this [cboCombo.ListIndex = -1] but not like this [cboCombo.SelText = ""]

    Thanks anyway
    Joon

  11. #11
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Are you sure you pasted the code I posted exactly?

    I'm using it here and it works exactly as you want it to, with the Combobox Style Set to DropDown List.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Hi Aaron,

    Yes, I copied exactly what u posted here, except that I changed "KeyCode" to "KeyAscii"

    Ur code worked as long as there r no items in the list that starts with second letter of what I typed in the combo box.

    For example, if there r "vs7" and "sc-7" in the list, it would bring up "sc-7" when I type "vs".

    I guess I'll have to change style of combo box. I use combo box dropdown list style, so that users don't accidently input wrong model since this style won't accept other than what's in the list.

    I just didn't want to go through whole list to make sure it's in the list every time user input models.

    On the other hands, by using dropdown list, users having a hard time for selecting models cuz there r a lot of models.

    Thanks
    Joon

  13. #13
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I see what's happening.. In order for this type of routine to work, your list needs to be sorted.

    Set the Sorted Property to True at Design Time.

    P.S. KeyCode was a Typo on my part.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Ur right Aaron.
    It works fine except one.

    I type "VS", and then I realize that it wasn't model that I want it and type "KD",
    It then matches item that starts with "D" by missing one character.

    I modified ur code a little by giving option to erase content when user type in wrong and by emptying the box when there r no matched item

    Code:
    Public Sub GetItemInComboBox(parCombo As ComboBox, parKeyAscii As Integer)
    
       Static sTyped As String
       Dim iIndex As Integer
          
       If parKeyAscii = vbKeyBack Then
          sTyped = ""
          parKeyAscii = 0
       Else
          sTyped = sTyped & Chr(parKeyAscii)
       End If
          
       iIndex = SendMessage(parCombo.hwnd, CB_FINDSTRING, 0, ByVal sTyped)
       If iIndex = -1 Then
          parCombo.ListIndex = -1
       ElseIf iIndex > -1 Then
          parCombo = parCombo.List(iIndex)
       Else
          sTyped = ""
          parKeyAscii = 0
       End If
       
    End Sub
    By the way, have u noticed that the KeyPress event won't recognize "Delete" key, one that next to End key, it detects "Del" with dot key as VbKeyDelete.

    U can use the VbKeyDelete constant to catch the "Delete" key in KeyUp and KeyDown events.

    Thanks again all who replied to my question, especially Aaron

    Joon

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