Chris
Chris

Reputation: 170

How to keep ComboBox from scrolling? C#

I have a ComboBox. It is critical that the user cannot scroll by accident and change the selected value.

How can I prevent the ComboBox from changing the value and text when the use scrolls? Thanks.

Visual Studio 2008

Upvotes: 1

Views: 6439

Answers (2)

JohnForDummies
JohnForDummies

Reputation: 980

combobox.MouseWheel += new MouseEventHandler(combobox_MouseWheel);

void combobox_MouseWheel(object sender, MouseEventArgs e)
{
    ((HandledMouseEventArgs)e).Handled = true;
}

Upvotes: 9

Rob Elliott
Rob Elliott

Reputation: 2008

If you don't want the user messing with the control, disable it. On another level however, if it's critical the user NOT use the control... maybe you should change the control.

ComboBox.Enabled = false;

Upvotes: 1

Related Questions