• ComboBox – Limit to List (VB6)

    Author
    Topic
    #408708

    I have values I loaded into a VB ComboBox. How do I limit the users to only entries on the list. I have code to autofill while typing so I have to keep it as a dropdown combo type so they can actually type into the field. I’d rather not use a 3rd party control. The following is the code I’m using to autofill and am wondering if it can be modified

    Public Const CB_FINDSTRING = &H14C

    Public Declare Function SendMessage Lib “user32” Alias _
    “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long

    Public Sub AutoFillComboBox(OurBox As ComboBox)
    Dim x As Long
    Dim StringLen As Long

    With OurBox
    StringLen = Len(.Text)
    If StringLen Then
    x = SendMessage(.hwnd, CB_FINDSTRING, -1&, ByVal .Text)
    .ListIndex = x
    .SelStart = StringLen
    .SelLength = Len(.Text) – StringLen
    End If
    End With

    End Sub

    Viewing 2 reply threads
    Author
    Replies
    • #865297

      What do you have in the Change event of the control?

      • #865566

        This is all:

        If iKeyCode 8 Then

        AutoFillComboBox cboLocation

        End If

        • #865601

          OK, so you’re using SendMessage to find the matching value in the list, right? What happens if there is no match, and what do you *want* to happen? One of the more frustrating aspects of VB controls is that there are so few prebuilt events like NotInList.

        • #865602

          OK, so you’re using SendMessage to find the matching value in the list, right? What happens if there is no match, and what do you *want* to happen? One of the more frustrating aspects of VB controls is that there are so few prebuilt events like NotInList.

      • #865567

        This is all:

        If iKeyCode 8 Then

        AutoFillComboBox cboLocation

        End If

    • #868181

      Change the combobox’s Style to 2 – Dropdown List.

    • #868182

      Change the combobox’s Style to 2 – Dropdown List.

    Viewing 2 reply threads
    Reply To: ComboBox – Limit to List (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: