I want to disable mouse wheel in UltraComboEditor. In other words, I don't want user to select the item by mouse wheel, they can just select item from drop down list. I've tried many ways and all failed. But MS comboBox can handle everything as I want.
Then I made an experiment between MS comboBox and UltraComboEditor. I find that UltraComboEditor can not handle mouse wheel event while MS comboBox can. I tried 3 ways to debug whether this control can capture mouse wheel event. Blow is the 3 ways of my experiment. I set several breakponts to ensure combobox can handle mouse wheel event. MS combo can enter all the breakponts but UltraCombo can't. Anyone can help me?
const int WM_MOUSEWHEEL = 0x020A;
protected override void WndProc(ref Message m) { //stop scroll if (m.Msg == WM_MOUSEWHEEL) { //but force next item int delta; if ((int)m.WParam > 0) { //up delta = 1; } else { //down delta = -1; } this.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
return; }
base.WndProc(ref m); }
protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); }
public Form1() { this.testUltraCmb1.MouseWheel += new MouseEventHandler(testUltraCmb1_MouseWheel); }
public void testUltraCmb1_MouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs; if (handledArgs != null) handledArgs.Handled = true; }
Hi,
The reason this doesn't work is that when the UltraComboEditor goes into edit mode, it displays a TextBox control over the edit area. It is this TextBox which is handling the MouseWheel message. So you need to handle the event on the TextBox.
private void Form1_Load(object sender, EventArgs e) { this.ultraComboEditor1.ControlAdded += new ControlEventHandler(ultraComboEditor1_ControlAdded); this.ultraComboEditor1.ControlRemoved += new ControlEventHandler(ultraComboEditor1_ControlRemoved); } void ultraComboEditor1_ControlRemoved(object sender, ControlEventArgs e) { TextBox textBox = e.Control as TextBox; if (textBox != null) textBox.MouseWheel -= new MouseEventHandler(ultraComboEditor1_MouseWheel); } void ultraComboEditor1_ControlAdded(object sender, ControlEventArgs e) { TextBox textBox = e.Control as TextBox; if (textBox != null) textBox.MouseWheel += new MouseEventHandler(ultraComboEditor1_MouseWheel); } void ultraComboEditor1_MouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs; if (handledArgs != null) handledArgs.Handled = true;
}
Thank you for your quick reply, Mike.
I have applied your code and I really can capture the mouse wheel event. But I still cannot forbid the Combo from change value by mouse wheel. If I set breakpoint both in MS comboBox's MouseWheel event and Ultra comboBox's MouseWheel event, then if I wheel mouse's middle button, MS comboBox will enter the breakpoint first and its text will not be changed, Ultra comboBox will change its text first then enter the breakpont. So it still not work as what I expected...
I tested out this code before I posted it and it worked fine for me. I think I vaguely recall that there used to be a bug that the control was not honoring the Handled property on the MouseWheel event args. So perhaps you just need to update to the latest service release.
Mike,
I've got the same issue. What latest service release are you talking about? I'm currently using 8 vol. 2.
How to get the latest service release - Infragistics Community
I applied the latest available Service Release (Version 20082.2194), but the problem persists.Just like imissfm reported UltraComboEditor scrolls first and then enters the MouseWheel event, which is too late to prevent the scroll.
Another discussion brought me to a solution, which made me happy:
http://community.infragistics.com/forums/p/43840/240659.aspx#240659
Thank you anyway, Bye
Hello community!
Thanks to this discussion I could solve part of my problem allready. But I'm stuck with another one:
I'm using an UltraComboEditor-derived control to display my own Tree-Structure within a DropDownButton. Everything works very fine.
As this control is used as a normal dialog control as well as in grid cells as their EditorControl, I found out, that all the needed events (Key-Events, DropDown-Events, ...) must be handled with the control itselfe as well as with the ExternalEditor.
The last issue to solve ist the MouseWheel. With this discussion I found out how to disable mouse wheeling in den dialog combos. But as an EditorControl the MouseWheel insists to work within a grid cell. Regrettfully there is no ControlAdded-Event with the combos ExternalEditor. Also the Grid's MouseWheel-Event will not fire.
Do you have any suggestions?
TIA
I used the MessageBox on purpose to force the form to lose focus to show that the ComboBox has already scrolled.
But you are absolutely right. My test project was using the old version of the dll's (8.2.20082.1000). So I changed the dll's manually to 8.2.20082.2194 and now the scroll works correctly. So this issue is resolved.
Thanks a lot!
Okay, I ran your sample and moved the mouse over the combo and spun my mouse wheel. I get a message box indicating that the event is firing correctly.
I took the message box out, because it's not a good idea to use message boxes for debugging. Forcing the form to lose focus to another window can often cause adverse affects to what you are trying to test.
Either way, with or without the message box, the combo does not scroll or change it's value in response to the mouse wheel on my machine. If this is not working for you, then my only guess is that you either don't have the latest service release installed or the project is not actually using it. Your project here is using v8.2. Perhaps you installed the service release for some other version?
A Solution (VS 2008) is attached.