Link to home
Start Free TrialLog in
Avatar of lrstratton
lrstratton

asked on

special combobox controls

I need a combobox which works like the combobox used by MS Outlook to select a person to send a meassage "To:".  It has a textbox above a listbox.  As text is entered into the textbox, a cursor moves down the listbox, highlighting the closest selection from the list.  A simple combobox is close, but it does not highlight the closest match.  I match the closest selection to retrieve data from my database and I don't want to query with incomplete input.
Avatar of bad_ima
bad_ima

Use the following code , (changing the combo1 with the name of your combobox) or try using the combobox or listbox from the "Microsoft Forms 2.0 Library".
P.S. You can modify this code to be with a textbox & listbox like in Outlook ... Just keep the idea ...



Dim strCombo As String
private Const WM_SETREDRAW = &HB
Private Const KEY_A = 65
Private Const KEY_Z = 90

Private Declare Function SendMessage Lib "User" _
       (ByVal hWnd As Integer, _
       ByVal wMsg As Integer, _
       ByVal wParam As Integer, _
       lParam As Any) As Long

Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim x%
Dim strTemp$
Dim nRet&
If Keycode >= KEY_A And Keycode <= KEY_Z Then
'     'only look at letters A-Z
strTemp = combo1.Text
If Len(strTemp) = 1 Then strCombo = strTemp
nRet& = SendMessage(combo1.hWnd, _
WM_SETREDRAW, False, 0&)

       For x = 0 To (combo1.ListCount - 1)
              If UCase((strTemp & _
              Mid$(combo1.List(x), _
              Len(strTemp) + 1))) =
              UCase(combo1.List(x)) Then
              combo1.ListIndex = x
              combo1.Text = combo1.List(x)
              combo1.SelStart = Len(strTemp)
              combo1.SelLength = _
              Len(combo1.Text) - (Len(strTemp))
              strCombo = strCombo & _
              Mid$(strTemp, Len(strCombo) + 1)
              Exit For
       Else
              If InStr(UCase(strTemp), _
              UCase(strCombo)) Then
              strCombo = strCombo & _
              Mid$(strTemp, Len(strCombo) + 1)
              combo1.Text = strCombo
              combo1.SelStart = Len(combo1.Text)
       Else
              strCombo = strTemp
       End If

End If

Next

nRet& = SendMessage(combo1.hWnd, _
WM_SETREDRAW, True, 0&)
End If

End Sub

Avatar of lrstratton

ASKER

When I try your code, I get the message:

Run-time error '48':

File not found: User

I do not have a user.dll in my system directory.  I am running Windows 95 and Visual Basic Version 5.  Should the Declare Function user "User32"?  When I do that, I get the message:

Run-time error '453':

Can't find DLL entry point SendMessage in User32

I believe the code bad_ima gave you was from 16-bit VB.  The correct declaration for the SendMessage API should be

Private Declare Function SendMessage alias "SendMessageA" Lib "User32" _
            (ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            lParam As Any) As Long

Good luck.
Sorry, that's right... I had it in a database and I forgot about this detail , which is realy important.

ASKER CERTIFIED SOLUTION
Avatar of nbishop
nbishop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial