This is the last 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 Const CB_GETCOMBOBOXINFO As Long = &H164
Private Const CB_SETEXTENDEDUI As Long = &H155
Private Const CB_FINDSTRINGEXACT = &H158
Private Const CB_FINDSTRING = &H14C
Private Const CB_SELECTSTRING = &H14D
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type COMBOBOXINFO
cbSize As Long
rcItem As RECT
rcButton As RECT
stateButton As Long
hwndCombo As Long
hwndItem As Long
hwndList As Long
End Type
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private mLastCombo1Text As String
Private mList(9) As String
Private Sub Combo1_Change()
Dim iStr As String
Dim iSS As Long
FillCombo
If Trim(Combo1.Text) <> "" Then
If Not ComboIsDropped(Combo1) Then
If Combo1.ListCount > 0 Then
iSS = Combo1.SelStart
iStr = Combo1.Text
DropDownCombo Combo1
Combo1.Text = iStr
Combo1.SelStart = iSS
Combo1.MousePointer = 1
Combo1.MousePointer = 0
End If
End If
End If
mLastCombo1Text = Combo1.Text
End Sub
Private Sub Combo1_Click()
If Combo1.ItemData(Combo1.ListIndex) = -1 Then
Combo1.Tag = "1"
Combo1.Clear
FillCombo
Combo1.Text = mLastCombo1Text
DropDownCombo Combo1
Else
If Combo1.ItemData(Combo1.ListIndex) = -2 Then
Combo1.Text = mLastCombo1Text
End If
End If
End Sub
Private Sub Combo1_DropDown()
FillCombo
End Sub
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) = "baa2"
SendMessage Combo1.hwnd, CB_SETEXTENDEDUI, 1, ByVal 0
End Sub
Private Sub FillCombo()
Dim c As Long
Dim iStr As String
Dim iStr2 As String
Dim iSDD As Boolean
Dim L As Long
Dim iSS As Long
If Combo1.Tag = "2" Then Exit Sub
iStr2 = Combo1.Text
iStr = Trim(iStr2)
iSS = Combo1.SelStart
iSDD = ComboIsDropped(Combo1)
If iSDD Then
ShowComboList Combo1, False
End If
Do Until Combo1.ListCount = 0
Combo1.RemoveItem 0
Loop
If Combo1.Tag = "1" Then
If Combo1.ListCount < 2 Then
For c = 0 To UBound(mList)
Combo1.AddItem mList(c)
Next c
End If
Combo1.Tag = "2"
Exit Sub
If iSDD Then
ShowComboList Combo1, True
End If
End If
For c = 0 To UBound(mList)
If InStr(mList(c), iStr) > 0 Then
Combo1.AddItem mList(c)
End If
Next c
If Combo1.ListCount < 2 Then
For c = 0 To UBound(mList)
Combo1.AddItem mList(c)
Next c
End If
If Combo1.ListCount < UBound(mList) + 1 Then
Combo1.AddItem "----------------"
Combo1.ItemData(Combo1.NewIndex) = -2
Combo1.AddItem "Show all"
Combo1.ItemData(Combo1.NewIndex) = -1
End If
If iSDD Then
ShowComboList Combo1, True
End If
If iStr2 <> "" Then
L = SendMessage(Combo1.hwnd, CB_FINDSTRINGEXACT, _
-1, ByVal iStr2)
Combo1.ListIndex = L
Combo1.SelStart = iSS
End If
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
Private Sub ShowComboList(nCombo As ComboBox, _
nShow As Boolean)
Dim iCbInfo As COMBOBOXINFO
iCbInfo.cbSize = Len(iCbInfo)
SendMessage nCombo.hwnd, CB_GETCOMBOBOXINFO, _
0&, iCbInfo
ShowWindow iCbInfo.hwndList, Abs(CLng(nShow))
End Sub