SmartMan123
IS-IT--Management
thread705-1227398
This code will use the arrow keys to cycle through the combobox list. I believe listindex is read only, combo.item(i) is what is used to set selected item.
This code will use the arrow keys to cycle through the combobox list. I believe listindex is read only, combo.item(i) is what is used to set selected item.
Code:
Public Sub ArrowKeys(ByRef KeyCode As Integer, combo As ComboBox, ByRef Flag As Boolean)
' flag is used to be able to toggle normal action in combo_change()
Select Case KeyCode
Case vbKeyDown
KeyCode = 0 ' make sure the action wont be duplicated
If combo.ListIndex <> combo.ListCount - 1 Then
combo.Value = combo.ItemData(combo.ListIndex + 1)
Flag = True
combo.Dropdown
Else
combo.Value = combo.ItemData(0)
Flag = True
combo.Dropdown
End If
Case vbKeyUp
KeyCode = 0 ' make sure the action wont be duplicated
If combo.ListIndex = -1 Then ' In case nothingg is selected yet (-1 index)
combo.Value = combo.ItemData(combo.ListCount - 1)
combo.Dropdown
ElseIf combo.ListIndex <> 0 Then
combo.Value = combo.ItemData(combo.ListIndex - 1)
Flag = True
combo.Dropdown
Else
combo.Value = combo.ItemData(combo.ListCount - 1)
Flag = True
combo.Dropdown
End If
End Select
End Sub