Hello,
I have an UltraGrid with a column called 'LandCodes'. I set the ValueList of this column and set the Style to ColumnStyle.DropDownList.
The scenario is:I select a value from the drop down for a 'LandCodes' cellI then scroll the mouse wheel
Currently this causes the value in the cell to change.
The behaviour I am looking for is the value no remain the same but for the grid to scroll.
Any help would be greatly appreciated.
Thanks,Paul
Hi Paul,
When you select an item from the list, the cell remains in edit mode. So the MouseWheel is handled by the cell's editor instead of by the grid. This is not different then if you tabbed into that cell or clicked on it without selecting a value.
Do you want to prevent the mouse wheel from working in ALL of those cases? Or just this one particular case?
If it's just this one case, then the thing to do would be to force the cell out of edit mode. But this will be very tricky and kinda weird for the user. first off, it will be very difficult to detect when the user is really "done" editing the cell. Suppose they drop down the list, pick an item, and then change their mind and try to type in the cell. If it's not in edit mode any more, then typing won't work. There is also no way to tell if the user drops down the list and picks something or drops down the list and clicks on some other cell without choosing anything. You can reliably detect when the list closes, though. So if you want to explore this option, you could do something like this:
private void ultraGrid1_AfterCellListCloseUp(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { UltraGrid grid = (UltraGrid)sender; grid.PerformAction(UltraGridAction.ExitEditMode); }
If you want to prevent the editor from handling the MouseWheel in all cases, then I'm not sure if that's possible. I would have to look into it some more.
Hi Mike,
Ideally I would like to prevent the mouse wheel from affecting the cell when ever the drop down list is not shown.
Some of my users are selecting a value from the drop down (either with the mouse or using the keyboard) and then attempt to use the mouse scroll wheel to scroll down the grid. Obviously it won't scroll but the problem is sometimes they do this and don't realise they've changed the value in the cell.
My initial solutions was as below but it doesn't work. The ControlAdded code runs and adds the handle but the ctrl_MouseWheel function is never called.
private bool allowCellScroll;
private void gridFdp_BeforeCellListDropDown(object sender, CancelableCellEventArgs e){ this.allowCellScroll = true;}private void gridFdp_AfterCellListCloseUp(object sender, CellEventArgs e){ this.allowCellScroll = false;}
allowCellScroll
this.allowCellScroll = false;
private void gridFdp_ControlAdded(object sender, ControlEventArgs e){ Infragistics.Win.UltraControlBase ctrl = e.Control as Infragistics.Win.UltraControlBase; if (ctrl != null) ctrl.MouseWheel += new MouseEventHandler(ctrl_MouseWheel);}
private void ctrl_MouseWheel(object sender, MouseEventArgs e){ HandledMouseEventArgs args = e as HandledMouseEventArgs; if (args != null && !this.allowCellScroll) args.Handled = true;}
this.allowCellScroll
Hi,
You need to handle the MouseWheel on the editor, not on the grid. There's sample code showing how to do this here:
How to let the cellvalue not changed together when scrolling the wheel of the mouse - NetAdvantage for Windows Forms - Grids
My code does handle the MouseWheel on the editor in addition the code in the example given doesn't work for DropDownList columns as tramp168 says.
Using the example the 'TextBox_MouseWheel' function is never called when you scroll the mouse in a cell which contains a drop down list (the value of the cell simply changes). The 'TextBox_MouseWheel' function is called if you scroll the mouse in a standard text cell but obviously that isn't helpful in this case.
It appears to me that the editor.TextBox is not the control I need to be handling the MouseWheel event for. What control is used in the grid for a DropDownList and is this control assesible in any way so I can handle the MouseWheel event on it?
My apologies, I misread the post I linked to. I didn't realize it was still using the TextBox. So that's actually no different than what you already did.
In DropDownList mode, there is no TextBox. You don't need one, since you can't type into the cell.
I did some investigating and it looks like what's happening in this case is that the Editor is actually listening in to the MouseWheel event of the the owning control - in this case the grid. So if you handle the grid's MouseWheel event, you are listening to the same event the editor is using and you cannot be sure that you will get the event before the editor does.
So the only reliable way to handle this would be to derive a class from the WinGrid and override the OnMouseWheel method. Then you could check the current state of the grid and if there is nothing dropped down, set e.Handled to True before calling the base.
That sounds slightly more painful than the 200 or so lines of code from the post you reference above where the mouse wheel MAY be handled in most cases when the dropdown display is not up.
Is there a better solution for this now? I'm noticing that even when cellActivation is set to ActivateOnly, the editor component still scrolls through it's list. I can disable the scroll behavior altogether by setting the CellActivation to NoEdit, but I would prefer to allow users to copy the value from the cell. Will we see a fix that actually prevents the cell's value from changing when ActivateOnly is set, regardless of the editor?
I tried this out with UltraCombo and it still works just fine for me. I don't have any problem with the mouse wheel.The mouse wheel still scrolls the grid and doesn't change the cell value.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand band = layout.Bands[0]; UltraGridOverride ov = layout.Override; UltraCombo cbo = new UltraCombo(); this.Controls.Add(cbo); DataTable dt = new DataTable(); dt.Columns.Add("Key", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Rows.Add(new object[] { 0, "Apple" }); dt.Rows.Add(new object[] { 1, "Banana" }); dt.Rows.Add(new object[] { 2, "Cherry" }); dt.Rows.Add(new object[] { 3, "Grape" }); dt.Rows.Add(new object[] { 4, "Watermelon" }); cbo.DataSource = dt; cbo.ValueMember = "Key"; cbo.DisplayMember = "Name"; band.Columns["Int32 1"].EditorComponent = cbo; band.Columns["Int32 1"].CellActivation = Activation.ActivateOnly; }
Why are you using UltraCombo and EditorComponent? That will work, of course, but it's not a very efficient way to do it. Unless you need the combo to provide editor buttons or multi-select, it would be better to use UltraDropDown as the ValueList of the column.
Not a problem; I see what you're doing and I agree, with a value list this problem does not occur. However, i'm setting the EditorComponent to an UltraCombo; this is when I'm seeing the undesired scroll behavior with CellActivation set to ActivateOnly
The forums will not allow me to update a file with an unknown extension like that.
Only files with the following extensions are allowed: zip, cab, jpg, gif, png, mpg, mpeg, avi, wmv, wma, mp3, ra, rar, rm, sql, txt.
All I did was put a grid on a form and bind it to a DataSource that has an integer field with values from 0 to 4.
Then I did this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand band = layout.Bands[0]; ValueList vl = new ValueList(); vl.ValueListItems.Add(0, "Apple"); vl.ValueListItems.Add(1, "Banana"); vl.ValueListItems.Add(2, "Cherry"); vl.ValueListItems.Add(3, "Grape"); vl.ValueListItems.Add(4, "Watermelon"); band.Columns["Int32 1"].ValueList = vl; band.Columns["Int32 1"].CellActivation = Activation.ActivateOnly; }
Mike, could you send the sample in a different way? (Zip, with the extension changed to zi_ might work) I believe our zealous Corporate email security software is stripping the attachment without giving me the option to retrieve it.
I should also mention that I am specifically using an UltraCombo as the Editor, and the latest release of Infragistics WinForms (13.2, updated 2 days ago)
I tried this out and I can't get the behavior you describe. The mouse wheel has no effect on a column where the CellActivation is set to ActivateOnly. When I use the wheel in a case like this, the grid scrolls, and the value of the cell does not change, which seems like correct behavior.
I'm attaching my sample here so you can try it and see if you get the same results.