Replacing
Combo with the actual name of your combobox:
- Private Sub Combo_KeyDown(KeyCode As Integer, Shift As Integer)
-
-
Select Case KeyCode
-
Case vbKeyDown
-
If Combo.ListIndex <> Combo.ListCount 1 Then
-
Combo.ListIndex = Combo.ListIndex + 1
-
Else
-
Combo.ListIndex = 0
-
End If
-
Case vbKeyUp
-
If Combo.ListIndex <> 0 Then
-
Combo.ListIndex = Combo.ListIndex 1
-
Else
-
Combo.ListIndex = Combo.ListCount 1
-
End If
-
End Select
-
-
End Sub
-
In order to keep focus from leaving the combobox when you get to the beginning or the end of the selections, I have it "wrapping." If you get to the last selection and hit the
Down Arrow again, it wraps back to the first selection ; if you're on the first selection and hit the
Up Arrow it wraps around to the last selection.
Remember, if for some reason you use this code elsewhere, without the combobox having the focus, you need to set focus on it before executing the code.
Linq
;0)>