I'm trying to achieve something similar like FireFox and other programs do
(Google in the search box), of making available on the combo dropdown list
just items that are relevant to what the user is typing.
I have several problems.
1) The mouse pointer disappears.
2) The list is not properly refreshed and the bottom part of the previous
list remains on the screen.
3) I don't know why the fist matching item is selected with the first
keystroke.
This is the 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_GETDROPPEDSTATE As Long = &H157
Private Const CB_SHOWDROPDOWN As Long = &H14F
Private mList(9) As String
Private Sub Form_Load()
mList(0) = "aaa"
mList(1) = "aa"
mList(2) = "abbbba"
mList(3) = "lla"
mList(4) = "lfaa"
mList(5) = "adffkaaa"
mList(6) = "baa"
mList(7) = "bbba"
mList(8) = "baba"
mList(9) = "baa"
End Sub
Private Sub Combo1_Change()
If Trim (Combo1.Text) <> "" Then
FillCombo
If Not ComboIsDropped(Combo1) Then
If Combo1.ListCount > 0 Then
DropDownCombo Combo1
End If
End If
Else
DropUpCombo Combo1
End If
End Sub
Private Sub FillCombo()
Dim c As Long
Dim iStr As String
iStr = Trim (Combo1.Text)
Do Until Combo1.ListCount = 0
Combo1.RemoveItem 0
Loop
For c = 0 To UBound(mList)
If InStr(mList(c), iStr) > 0 Then
Combo1.AddItem mList(c)
End If
Next c
End Sub
Public Function ComboIsDropped(nCombo As ComboBox) As Boolean
ComboIsDropped = CBool(SendMessage(nCombo.hwnd, _
CB_GETDROPPEDSTATE, 0&, 0&))
End Function
Public Sub DropDownCombo(nCombo As ComboBox)
SendMessage nCombo.hwnd, CB_SHOWDROPDOWN, _
True, ByVal 0
End Sub
Public Sub DropUpCombo(nCombo As ComboBox)
SendMessage nCombo.hwnd, CB_SHOWDROPDOWN, _
False, ByVal 0
End Sub
Replies