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...
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.
As I said, I tried this out and it worked fine for me. So if this is happening, we will need to be able to duplicate it. Can you provide a small sample project demonstrating the issue and post it here so we can check it out?
Here is the complete code. The version number of the Infragistics controls I used is 20082.2194. When the Form opens, UltraComboEditor gets focus.Turn the mouse wheel with the mouse pointer anywhere on the screen.
public class Form1 : Form { public Form1() { InitializeComponent(); }
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows Form Designer generated code private void InitializeComponent() { Infragistics.Win.ValueListItem valueListItem1 = new Infragistics.Win.ValueListItem(); Infragistics.Win.ValueListItem valueListItem2 = new Infragistics.Win.ValueListItem(); Infragistics.Win.ValueListItem valueListItem3 = new Infragistics.Win.ValueListItem(); Infragistics.Win.ValueListItem valueListItem4 = new Infragistics.Win.ValueListItem(); this.ultraComboEditor1 = new Infragistics.Win.UltraWinEditors.UltraComboEditor(); ((System.ComponentModel.ISupportInitialize)(this.ultraComboEditor1)).BeginInit(); this.SuspendLayout(); // // ultraComboEditor1 // valueListItem1.DataValue = 1; valueListItem1.DisplayText = "Item1"; valueListItem2.DataValue = 2; valueListItem2.DisplayText = "Item2"; valueListItem3.DataValue = 3; valueListItem3.DisplayText = "Item3"; valueListItem4.DataValue = 4; valueListItem4.DisplayText = "Item4"; this.ultraComboEditor1.Items.AddRange(new Infragistics.Win.ValueListItem[] { valueListItem1, valueListItem2, valueListItem3, valueListItem4}); this.ultraComboEditor1.Location = new System.Drawing.Point(12, 12); this.ultraComboEditor1.Name = "ultraComboEditor1"; this.ultraComboEditor1.Size = new System.Drawing.Size(260, 21); this.ultraComboEditor1.TabIndex = 0; this.ultraComboEditor1.Text = "Item1"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 264); this.Controls.Add(this.ultraComboEditor1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.ultraComboEditor1)).EndInit(); this.ResumeLayout(false); this.PerformLayout();
#endregion
private Infragistics.Win.UltraWinEditors.UltraComboEditor ultraComboEditor1;
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;
MessageBox.Show("MouseWheel is called AFTER 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.