Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ComboBox - Limit to List (VB6)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - Limit to List (VB6)

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

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - Limit to List (VB6)

    This is all:

    If iKeyCode <> 8 Then

    AutoFillComboBox cboLocation

    End If

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - Limit to List (VB6)

    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.
    Charlotte

  5. #5
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - Limit to List (VB6)

    Change the combobox's Style to 2 - Dropdown List.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •