Hi, i'm having a combobox with 12 items and I would like to scroll these items
with my mouse disabled (only with my keyboard).
Is there an example how to achieve this?
Thanks in advance for your answers.
Printable View
Hi, i'm having a combobox with 12 items and I would like to scroll these items
with my mouse disabled (only with my keyboard).
Is there an example how to achieve this?
Thanks in advance for your answers.
Set focus to the combobox and press the down/up arrows. Otherwise, how do you plan on scrolling? Let's say you use the Down/Up arrows and trap them before other controls get them (Form's KeyPreview property set to True). Now you can change the ListIndex of the combobox to "scroll". However, if you trap those keys, then other controls won't have them either, like a textbox, richtexboxt, and other scrollable controls. Can you give more details?
Welcome to the forums.
Hi LaVolpe,
my Form's KeyPreview is set to true. I have no problems with my keys or my keyboard, the problem is my mouse and its wheel. With so many items, I have in my combobox a scrollbar, scrollable with mouse. My client wants, that mouse scrolling with its wheel is disabled and wants, that items in combobox are scrollable only with keyboard (up or down). It is a weird request and I have no idea, how to achieve this.
For each up/down arrow action, simply change the ListIndex of the combobox.
Code:' moving down in the list
If Combo1.ListIndex = Combo1.ListCount -1 Then ' on last list item
Combo1.ListIndex = 0 ' move to first or don't move at all; your choice
Else
Combo1.ListIndex = Combo1.ListIndex + 1
End If
' scrolling up; pretty much the reverse
If Combo1.ListIndex = 0 Then ' at the top of the list
Combo1.ListIndex = Combo1.ListCount -1 ' move to bottom or don't move at all
Else
Combo1.ListIndex = Combo1.ListIndex -1
End If
If you know subclassing this will be easy
a simple way for subclassing is the SmartSubclass Library, you can download it from this link SmartSubclass DLL
- create a new project with a combobox named combo1 and has any no of items
- extract the file "SmartSubClass.dll"
- reference it : Project --> references --> Browse --> select the file --> open --> ok
- in Form1 code module insert the following code:
Code:Option Explicit
Dim WithEvents oSniff As SmartSubClassLib.SmartSubClass
Private Sub Form_Load()
Set oSniff = New SmartSubClassLib.SmartSubClass
oSniff.SubClassHwnd Combo1.hWnd, True
End Sub
Private Sub Form_Unload(Cancel As Integer)
oSniff.SubClassHwnd Combo1.hWnd, False
End Sub
Private Sub oSniff_NewMessage(ByVal hWnd As Long, uMsg As Long, wParam As Long, lParam As Long, Cancel As Boolean)
Select Case hWnd
Case Combo1.hWnd
Select Case uMsg
Case &H20A&
uMsg = 0
End Select
End Select
End Sub
Amr Al-Amir, this is what I was searching for! Thank you very much for your reply :)
You are welcome
This works fine. If you have the time, I would like to know how to get my 'dropdown combo' to drop down. I've tried hacking in some code into your oSniff sub; but nothing I've tried works. I really need this functionality and would be very appreciative of your help.
Thanks,
Bob DeVore
Hi Bob,
it should be enough, if the style of your Combobox is 0 - Dropdown Combo. You can set his style in the Properties Window.
No need for the oSniff things
create a new project with a combobox named combo1 and a command button Named command1, populate the combobox list (may be from the 'list' property) and into the form insert this code
Code:Option Explicit
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_SHOWDROPDOWN = &H14F
Private Sub Command1_Click()
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0
End Sub