Results 1 to 10 of 10

Thread: [RESOLVED] Scrolling Combobox without mouse wheel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    17

    Resolved [RESOLVED] Scrolling Combobox without mouse wheel

    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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Scrolling Combobox without mouse wheel

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    17

    Re: Scrolling Combobox without mouse wheel

    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.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Scrolling Combobox without mouse wheel

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Lively Member
    Join Date
    Mar 2007
    Posts
    88

    Re: Scrolling Combobox without mouse wheel

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    17

    Re: Scrolling Combobox without mouse wheel

    Amr Al-Amir, this is what I was searching for! Thank you very much for your reply

  7. #7
    Lively Member
    Join Date
    Mar 2007
    Posts
    88

    Re: [RESOLVED] Scrolling Combobox without mouse wheel

    You are welcome

  8. #8
    New Member
    Join Date
    Mar 2009
    Posts
    1

    Re: Scrolling Combobox without mouse wheel

    Quote Originally Posted by Amr Al-Amir View Post
    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
    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

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    17

    Re: Scrolling Combobox without mouse wheel

    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.

  10. #10
    Lively Member
    Join Date
    Mar 2007
    Posts
    88

    Re: [RESOLVED] Scrolling Combobox without mouse wheel

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width