- Код: Выделить всё
'некорректный выбор значения
Option Explicit
Private Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_SETCURSEL = &H14E
Dim fHideList As Boolean
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
fHideList = True
ComboListVisible Combo1, False
End If
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim lRet As Long
If fHideList Then fHideList = False: Exit Sub
ComboListVisible Combo1, True
If KeyCode = 13 Then
Debug.Print Combo1.ListIndex
End If
If KeyCode = vbKeyDelete Or KeyCode = vbKeyBack Then
Combo1.ListIndex = -1
'lRet = SendMessageLong(Combo1.hwnd, CB_SETCURSEL, -1, 0) 'снять выделение
End If
End Sub
Private Sub ComboListVisible(Combo As ComboBox, ByVal Flag As Boolean)
Dim Mess As Long
Mess = SendMessageLong(Combo.hwnd, CB_SHOWDROPDOWN, Flag, 0)
Combo.MousePointer = 0 'иначе мышь пропадает при вводе некого значения и нажатия Enter
End Sub
Private Sub Form_Load()
Dim i As Long
For i = 1 To 9
Combo1.AddItem i
Next i
Combo1.AddItem "100"
End Sub