Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread705-1227398 This code will

Status
Not open for further replies.

SmartMan123

IS-IT--Management
Aug 23, 2020
3
EG
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.

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
 
> I believe listindex is read only

You believe wrong, as was indicated in that original thread; you just need to make sure the combobox has focus

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top