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!
What version of the grid are you using? I tried this out and the MouseWheel scrolls the dropdown when it's dropped down or the grid when it is not dropped down. It never changes the value or the cell or scrolls both at the same time.
I use for .net 2008 vol 3.
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;}
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.
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;
for column style dropdownlist I solved the problem as follows:
myUltraGrid.MouseWheel += UltraGrid_MouseWheel;
static void UltraGrid_MouseWheel(object sender, MouseEventArgs e) { UltraGrid ugSender = sender as UltraGrid; if (ugSender.ActiveCell != null) { UltraDropDown dropDown = ugSender.ActiveCell.ValueListResolved as UltraDropDown; if (dropDown != null) { if (!dropDown.IsDroppedDown) { ((HandledMouseEventArgs)e).Handled = true; ugSender.PerformAction(UltraGridAction.ExitEditMode, false, false); } } } }}You are able to scroll if ultradropdown is dropped down, otherwise not.
Incase anyone is interested I have translated the original sample nto vb.net, it was not easy! I have also altered it so A) clicking on something such as a datetime editor don't crash it and B) I have enabled scrolling when the drop down is showing so you can scroll up and down the list but only if its displayed.
'These next four functions override mouse scrolling to prevent accidental scrolling.
'Add a handler that returns handled to prevent scrolling (see under events).
Private Sub ugrScenario_AfterEnterEditMode(sender As System.Object, e As System.EventArgs) Handles ugrScenario.AfterEnterEditMode
Dim editor As EditorWithText = Nothing
Dim activegrid As Infragistics.Win.UltraWinGrid.UltraGrid
activegrid = CType(sender, Infragistics.Win.UltraWinGrid.UltraGrid)
If IsNothing(activegrid.ActiveCell) = False Then
If TypeOf (activegrid.ActiveCell.EditorResolved) Is EditorWithText Then
editor = CType(activegrid.ActiveCell.EditorResolved, EditorWithText)
End If
If IsNothing(editor) = False Then
'Add custom handler
RemoveHandler editor.TextBox.MouseWheel, AddressOf textBox_MouseWheel
AddHandler editor.TextBox.MouseWheel, AddressOf textBox_MouseWheel
End Sub
'Re-enable scrolling when the cell is exited.
Private Sub ugrScenario_AfterExitEditMode(sender As System.Object, e As System.EventArgs) Handles ugrScenario.AfterExitEditMode
'Remove custom handler
'Allow scrolling if the drop down list is showing.
Private Sub ugrScenario_BeforeCellListDropDown(sender As System.Object, e As Infragistics.Win.UltraWinGrid.CancelableCellEventArgs) Handles ugrScenario.BeforeCellListDropDown
Private Sub ugrScenario_AfterCellListCloseUp(sender As System.Object, e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles ugrScenario.AfterCellListCloseUp
'Add and remove custom handler
'Mouse event.
Private Sub textBox_MouseWheel(sender As Object, e As MouseEventArgs)
Dim theTextbox As TextBox
Dim ugrid As Infragistics.Win.UltraWinGrid.UltraGrid = Nothing
Dim activeCell As Infragistics.Win.UltraWinGrid.UltraGridCell = Nothing
Dim activeCol As Infragistics.Win.UltraWinGrid.UltraGridColumn = Nothing
Dim hasValueList As Boolean = False
Dim handledArgs As HandledMouseEventArgs
theTextbox = CType(sender, TextBox)
If IsNothing(theTextbox) = False Then
ugrid = theTextbox.Parent
'Determine whether the cell in edit mode is associated with
' a ValueList.
If IsNothing(ugrid.ActiveCell) = False Then
activeCell = ugrid.ActiveCell
activeCol = activeCell.Column
If IsNothing(activeCol.ValueList) = False Then
hasValueList = True
If hasValueList = True Then
'Mark the MouseWheel event handled to prevent the wheel from
'scrolling through the ValueList items
handledArgs = CType(e, HandledMouseEventArgs)
If IsNothing(handledArgs) = False Then
handledArgs.Handled = True
Brian Fallon, I must appreciate your kind help first!
the frmUltraDropDown in the SamplesExplorer of the winGrid(you provided samples) has the same issue,in the third level ultrgrid, after product columnselect value from the ultrDropDown, then you scroll the mouse wheel in the product column,even if I add the code you given last time,the cell value changed too,you try with this( frmUltraDropDown )? if it is OK, Can you paste all the codes in the frmUltraDropDown for me?
Thank you !
I can't get thisto compile, so if you want me to solve your problem you will have to attach a VS project that compiles so I can debug it. The code I posted works in a simple project, and it looks like you used it in this code sample, so I really don't have an explanation as to why it isn't working for you.
#region using redirectivesusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System;using System.Collections.Generic;using System.ComponentModel;using System.Collections;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;using TX.DataAccess;using TX.FrameWorks;using TX.Winforms;using TX.Winforms.Components;using TX.Winforms.DesignerForms;using LT.Master.DataAccess;using TX.Winforms.UsualMethods;using LT.Routine.DataAccess;using LT.Reports.FormLibraries;using Infragistics.Win.UltraWinGrid;#endregion
namespace LT.Routine.FormLibraries{ public partial class frmRouting : Form { #region variable LoadTreeeView m_LoadTree = new LoadTreeeView(); private UltraGridRow m_MotionNo; private UltraGridCell m_UltraGridCell; private string strFilePath; private string strActionlog; private string strAssCode; private string strFlag; DataTable dt; SqlExecuteMaster m_SqlExecuteMaster; bool load = false; #endregion
public frmRouting() { InitializeComponent(); m_SqlExecuteMaster = new SqlExecuteMaster(); //this.ultraGrid.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.ultraGrid_MouseWheel); //this.ultraGrid.MouseWheel += new System.EventHandler(this.ultraGrid_MouseWheel); //System.EventHandler
this.ultraGrid.AfterEnterEditMode += new EventHandler(ultraGrid_AfterEnterEditMode); this.ultraGrid.AfterExitEditMode += new EventHandler(ultraGrid_AfterExitEditMode); }
#region System Events (ultraGrid1)
private void ultraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e) { this.ultraGrid.DisplayLayout.Override.ActiveRowAppearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
this.ultraGrid.DisplayLayout.Override.HeaderAppearance.BackColor = SystemColors.GradientActiveCaption; this.ultraGrid.DisplayLayout.Override.FixedCellAppearance.BackColor = SystemColors.GradientActiveCaption; this.ultraGrid.DisplayLayout.Appearance.BackColor = Color.White; this.ultraGrid.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.Blue; this.ultraGrid.DisplayLayout.Override.RowAlternateAppearance.BackColor = Color.FromArgb(211, 208, 200);
this.ultraGrid.DisplayLayout.Bands[0].Columns["Select"].Header.Caption = "SELECT"; this.ultraGrid.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].Header.Caption = "ProcessArea"; this.ultraGrid.DisplayLayout.Bands[0].Columns["WSBranchTypeNo"].Header.Caption = "ProcessType"; this.ultraGrid.DisplayLayout.Bands[0].Columns["MotionNo"].Header.Caption = "ProcessName"; this.ultraGrid.DisplayLayout.Bands[0].Columns["MachineName"].Header.Caption = "Machine"; this.ultraGrid.DisplayLayout.Bands[0].Columns["Times"].Header.Caption = "ProcessCount"; this.ultraGrid.DisplayLayout.Bands[0].Columns["PerMotionTime"].Header.Caption = "StdTime)"; this.ultraGrid.DisplayLayout.Bands[0].Columns["Times*PerMotionTime"].Header.Caption = "TotalHour"; this.ultraGrid.DisplayLayout.Bands[0].Columns["PiecesPerHour"].Header.Caption = "PCs/Hour"; this.ultraGrid.DisplayLayout.Bands[0].Columns["UnitPrice"].Header.Caption = "UnitPrice"; this.ultraGrid.DisplayLayout.Bands[0].Columns["TotalAmount"].Header.Caption = "TotalAmount"; this.ultraGrid.DisplayLayout.Bands[0].Columns["WorkSeqLevel"].Header.Caption = "ProcessAmount"; this.ultraGrid.DisplayLayout.Bands[0].Columns["TotalHour"].Header.Caption = "TotalTime"; this.ultraGrid.DisplayLayout.Bands[0].Columns["EmpCount"].Header.Caption = "EmpCount"; this.ultraGrid.DisplayLayout.Bands[0].Columns["Remark"].Header.Caption = "Remark";
this.ultraGrid.DisplayLayout.Bands[0].Columns["Times*PerMotionTime"].CellActivation = Activation.NoEdit; this.ultraGrid.DisplayLayout.Bands[0].Columns["TotalAmount"].CellActivation = Activation.NoEdit; this.ultraGrid.DisplayLayout.Bands[0].Columns["PiecesPerHour"].CellActivation = Activation.NoEdit; this.ultraGrid.DisplayLayout.Bands[0].Columns["TotalHour"].CellActivation = Activation.NoEdit; this.ultraGrid.DisplayLayout.Bands[0].Columns["EmpCount"].CellActivation = Activation.NoEdit; }
#endregion
private void frmRoutingNew_Load(object sender, EventArgs e) { ConfigureUltraDropDown(); InitLoad(); ultraGrid.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.RowIndex; }
#region User-defined methods and properties private void InitLoad() { this.DDHeadType.ValueMember = "SiteCode"; this.DDHeadType.DisplayMember = "SiteName"; this.ultraGrid.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate; this.ultraGrid.DisplayLayout.Bands[0].Columns["WSHeadTypeNo"].ValueList = this.DDHeadType; }
private void ConfigureUltraDropDown() { this.DDHeadType.DataSource = TX.Winforms.DataAccess.CommonData.GetWSHeadType(1); this.DDHeadType.DisplayLayout.Bands[0].Columns["SiteCode"].Width = 100; this.DDHeadType.DisplayLayout.Bands[0].Columns["SiteCode"].Header.Caption = "ProcessAreaCode"; this.DDHeadType.DisplayLayout.Bands[0].Columns["SiteName"].Width = 200; this.DDHeadType.DisplayLayout.Bands[0].Columns["SiteName"].Header.Caption = "ProcessAreaName"; this.DDHeadType.DisplayLayout.Override.RowAlternateAppearance.BackColor = Color.FromArgb(211, 208, 200); } #endregion
private void ultraGrid_AfterEnterEditMode(object sender, EventArgs e) { UltraGrid control = sender as UltraGrid; UltraGridCell activeCell = control != null ? control.ActiveCell : null; Infragistics.Win.EditorWithText editor = activeCell != null ? activeCell.EditorResolved as Infragistics.Win.EditorWithText : null; if (editor != null) { editor.TextBox.MouseWheel -= new MouseEventHandler(TextBox_MouseWheel); editor.TextBox.MouseWheel += new MouseEventHandler(TextBox_MouseWheel); } }
private void ultraGrid_AfterExitEditMode(object sender, EventArgs e) { UltraGrid control = sender as UltraGrid; UltraGridCell activeCell = control != null ? control.ActiveCell : null; Infragistics.Win.EditorWithText editor = activeCell != null ? activeCell.EditorResolved as Infragistics.Win.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;
// 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; }
}}
Above is all the main codes for the ultragrid and ultraDropDown , Can you help me to handle it?
Very very thank you !