Jake
Jake

Reputation: 11430

Disable mousewheel on combo box and bubble to parent

I have a nested control layout as such:

Form (user form) > TabControl > UserControl (autoscroll, docked-fill) > GroupBox (docked-top) > ComboBox

One UX problem is that the focus is most of the time in one of the input boxes. When the input box is a combobox, the combobox change the selection, which is not desired. I want the scroll to keep the combobox in focus while scrolling the UserControl.

I tried

combobox.MouseWheel += (s, e) => combobox.Parent.Focus();

but this seems to happen after the selection is changed. TextBox on the other hand works just fine. Is there a way to make combobox behave like a TextBox on mousewheel?

Upvotes: 0

Views: 1263

Answers (1)

tam tam
tam tam

Reputation: 1900

I had a scenario like this a few months back: I had ribbon tabs, buttons, textboxes,comboboxes in each tab. I wanted to scroll down and up with my mouse wheel (for the combobox), but instead, my mouse wheel changed the tabs. It didnt affect the combobox.

I then created my own class that inherits from that Ribbon control.

public class MyRibbon : Ribbon {

  public bool DisableMouseWheel { get; set; }

  protected override void OnMouseWheel(MouseEventArgs e) {
    if (!this.DisableMouseWheel) {
      base.OnMouseWheel(e);
    }
  }
}

I then Rebuild my solution. Clicked on the "Show All Files" button from the Solution Explorer and opened the designer file for the form. There were \two lines in the file that referenced the Ribbon type,I replaced the type with the new MyRibbon class.

Then I subscribed to the ComboBox's Enter and Left events where I changed the DisableMouseWheel property.

Upvotes: 1

Related Questions