Results 1 to 2 of 2

Thread: [RESOLVED] how to conditionally disable mouse wheel scrolling on custom combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    74

    Resolved [RESOLVED] how to conditionally disable mouse wheel scrolling on custom combobox

    I have a custom control which inherits from ComboBox. Its constructor sets the .DropDownStyle property to DropDownList (which I need it to be in all cases). I notice that if the user scrolls the mouse wheel while the cursor is over an instance of the custom control, it changes the selected item, EVEN when the custom control does not have the focus. This makes it much too easy to inadvertently change the selected item without knowing you've done so. What I want to do is have the control ignore the mouse wheel unless it has the focus (or possibly unless it has the focus AND the .DroppedDown property is True). I've tried the following code, and multiple variations on it, but it just disables the mouse wheel in all cases (even if .DroppedDown is True). Is there a way to do what I want here?

    Code:
        
    Protected Overrides Sub OnMouseWheel(e As MouseEventArgs)
        Dim hmwe As HandledMouseEventArgs = DirectCast(e, HandledMouseEventArgs)
        If Not Me.DroppedDown Then
            hmwe.Handled = True
        End If
        MyBase.OnMouseWheel(e)
    End Sub

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    74

    Re: how to conditionally disable mouse wheel scrolling on custom combobox

    Oops, nevermind! After further testing, I've found that this code DOES work as intended. Previously, I'd only tested it on controls where the entire list is visible at once, which won't scroll in any case.

Tags for this Thread

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