There is an ultraGrid(named ultraGrid1) and an ultrDropDown(named DDHeadType), the WSHeadTypeNo column's valus is from DDHeadType, now when in the editmode, when I scroll the wheel of the mouse, How to let the data of the WSHeadTypeNo cell in the ultrGrid not to change together? (below a little code to explain the relation and data)
this.DDHeadType.DataSource = datatableDheadtype
this.ultraGrid1.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate; this.ultraGrid1.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].ValueList = this.DDHeadType;
How to realize it? Thanks in advance!
When using the DropDownValidate style, the editor places a TextBox in the cell when it goes into edit mode. The code I posted handles that scenario, but if you can't get it working, you can attach a sample and I'll tweak it for you. When using the DropDownList style, however, you would hook the grid's MouseWheel event instead, and put that same code in there.
Even if I change the the "WSHeadTypeNo" column's Style from DropDownValidate to DropDownList(below is code), but the cell still change while scrolling the mouse wheel.
this.ultraGrid1.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
Brian Fallon, Thank you for your kind and patient help!
But I do as you wrote, it can not prevent the cell value changed while scrolling the mouse wheel.
I just verified that scrolling the mouse wheel does in fact change the cell value when a ValueList is assigned because the editor cycles through the items in the list when the wheel is scrolled, just like the ComboBox control does (we patterned the editor's behavior after this).
I see that I oversimplified my response previously; the editor does not forward the mouse wheel message to the grid as I thought it did, so you have to handle the MouseWheel event for the editor's TextBox instead. The following code sample demonstrates how to do that:
this.ultraGrid.AfterEnterEditMode += new EventHandler(ultraGrid_AfterEnterEditMode);this.ultraGrid.AfterExitEditMode += new EventHandler(ultraGrid_AfterExitEditMode);
void ultraGrid_AfterEnterEditMode(object sender, EventArgs e){ // Hook the editor's TextBox.MouseWheel event when edit mode is entered UltraGrid control = sender as UltraGrid; UltraGridCell activeCell = control != null ? control.ActiveCell : null; EditorWithText editor = activeCell != null ? activeCell.EditorResolved as EditorWithText : null; if ( editor != null ) { editor.TextBox.MouseWheel -= new MouseEventHandler(TextBox_MouseWheel); editor.TextBox.MouseWheel += new MouseEventHandler(TextBox_MouseWheel); }}
void ultraGrid_AfterExitEditMode(object sender, EventArgs e){ // Unhook from the editor's TextBox.MouseWheel event when edit mode ends UltraGrid control = sender as UltraGrid; UltraGridCell activeCell = control != null ? control.ActiveCell : null; EditorWithText editor = activeCell != null ? activeCell.EditorResolved as EditorWithText : null; if ( editor != null ) editor.TextBox.MouseWheel -= new MouseEventHandler(TextBox_MouseWheel);}
void TextBox_MouseWheel(object sender, MouseEventArgs e){ // You can get the ActiveCell this way if you need to TextBox textBox = sender as TextBox; UltraGrid grid = textBox != null ? textBox.Parent as UltraGrid : null; UltraGridCell activeCell = grid != null ? grid.ActiveCell : null;
// You can determine whether the cell in edit mode is associated with // a ValueList this way if you need to UltraGridColumn column = activeCell != null ? activeCell.Column : null; bool hasValueList = column != null && column.ValueList != null;
// Mark the MouseWheel event handled to prevent the wheel from // scrolling through the ValueList items HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs; if ( handledArgs != null ) handledArgs.Handled = true;}
I use for .net 2008 vol 3.