When an UltraDropDown is activated (i.e. single clicked) in my grid and the mouse scroll wheel moved the selected value in the UltraDropDown changes even though it has not dropped down. Typically my users are just wanting to scroll the grid in this situation. What do I need to change to make the grid scroll and not the UltraDropDown in this situation?
I am currently using 2007 Vol. 2 but can switch to the latest release if necessary.
KJSitton said:What do I need to change to make the grid scroll and not the UltraDropDown in this situation?
KJSitton, did you have any luck with this? I tried support, but they gave the old " I apologize but as such there is no intrinsic feature to achieve the desired behavior" answer.
If you have had some success with this, I'd appreciate it if you could share it with me.
Thanks.
Are there any news about this Problem?
Thanks for reply!
fweeee said:Its funny that you should ask that now. After working on this issue off and on since my previous post (5+ months), I finally arrived at a solution last night. Its dissapointing that I had to spend so much time (I would guess days) to acheive what I beleive should be standard functionality (or at least a standard option). But as far as I'm concerned, I couldnt release the application the way it was - it would just casue to many problems.Anyway, enough with my rant, onto the solution. I created a class to do this, to save writing it in each form individually. declare an object varaible to store the value of the dropdown field:
Its funny that you should ask that now. After working on this issue off and on since my previous post (5+ months), I finally arrived at a solution last night. Its dissapointing that I had to spend so much time (I would guess days) to acheive what I beleive should be standard functionality (or at least a standard option). But as far as I'm concerned, I couldnt release the application the way it was - it would just casue to many problems.
Anyway, enough with my rant, onto the solution. I created a class to do this, to save writing it in each form individually.
declare an object varaible to store the value of the dropdown field:
Thank you for sharing your solution, you saved me a lot of time :-)
Now, I'll share my version of this solution.I'm a VB developer, so i converted your solution in VB (and then, reconverted in C# using .Net Reflector ;-).I've fixed 2 issue:
*) in the dropdown close-up event, the value is still the old one; to get the right value we need to look something likeMe.mUGrid.ActiveCell.ValueListResolved.GetValue(Me.mUGrid.ActiveCell.ValueListResolved.SelectedItemIndex)
*) I've added a KeyUp event handler to track the value change due to user keyboard interaction with the UDD control
The VB version works, I've converted it in C# using .Net reflector, I don't know if it works, but at least it compile :-)
------------------------------------------------------------------
VB version
Imports Infragistics.Win.UltraWinGridImports System.Windows.FormsPublic Class UltraGridUddMouseWheelHack Public mUgrid As UltraGrid Private mUddSavedValueForMouseWheelHack As Object Public Sub InigUltraGridUddMouseWheelHack() AddHandler Me.mUgrid.ControlAdded, AddressOf Me.mUGrid_ControlAdded End Sub Private Sub mUGrid_ControlAdded(ByVal sender As Object, ByVal e As ControlEventArgs) 'Dim contType As String = sender.GetType().ToString() Dim uGrid As UltraGrid = DirectCast(sender, UltraGrid) Dim udd As UltraDropDown = TryCast(uGrid.ActiveCell.ValueListResolved, UltraDropDown) If (udd IsNot Nothing) Then AddHandler e.Control.MouseWheel, AddressOf mUGrid_uddControl_MouseWheel AddHandler e.Control.KeyUp, AddressOf mUGrid_uddControl_KeyUp AddHandler e.Control.Enter, AddressOf mUGrid_uddControl_Enter AddHandler udd.AfterCloseUp, AddressOf mUGrid_uddControl_AfterCloseUp End If End Sub Private Sub SaveUltraDropDownSelectedValue() '_dropdownValue = Me.mUGrid.ActiveCell.Value 'this one is wrong, when dthe dropdown close up, the activecell.value is still the old value; the grid update it later; so we need to picku up the corret value somwhere else (see down) If Me.mUgrid.ActiveCell IsNot Nothing AndAlso Me.mUgrid.ActiveCell.ValueListResolved IsNot Nothing Then mUddSavedValueForMouseWheelHack = Me.mUgrid.ActiveCell.ValueListResolved.GetValue(Me.mUgrid.ActiveCell.ValueListResolved.SelectedItemIndex) End If End Sub Private Sub mUGrid_uddControl_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 'this tack the value change due to keyboard interaction SaveUltraDropDownSelectedValue() End Sub Private Sub mUGrid_uddControl_AfterCloseUp(ByVal sender As Object, ByVal e As DropDownEventArgs) 'this tack the selected value on dropdown close-up SaveUltraDropDownSelectedValue() End Sub Private Sub mUGrid_uddControl_Enter(ByVal sender As Object, ByVal e As EventArgs) 'save the current value, used in case the user don't change the current value, but still use the mouse wheel Dim senderControl As Control = DirectCast(sender, Control) Dim uGrid As UltraGrid = TryCast(senderControl.Parent, UltraGrid) If (uGrid IsNot Nothing) Then Dim dropdown As UltraDropDown = TryCast(uGrid.ActiveCell.ValueListResolved, UltraDropDown) If (dropdown IsNot Nothing) Then mUddSavedValueForMouseWheelHack = uGrid.ActiveCell.Value End If End If End Sub Private Sub mUGrid_uddControl_MouseWheel(ByVal sender As Object, ByVal e As MouseEventArgs) Dim conSender As Control = DirectCast(sender, Control) Dim ugSender As UltraGrid = DirectCast(conSender.Parent, UltraGrid) If (ugSender IsNot Nothing) Then Dim dropdown As UltraDropDown = TryCast(ugSender.ActiveCell.ValueListResolved, UltraDropDown) If (dropdown IsNot Nothing) AndAlso (Not dropdown.IsDroppedDown) Then 'we need to restore the saved value because when this event handler is called, the 'udd current value has ALREADY been changed by this event, and this is exactly what mustn't happen ugSender.ActiveCell.Value = mUddSavedValueForMouseWheelHack 'from now-on, the mouse wheel will scroll the grid :-) ugSender.PerformAction(UltraGridAction.ExitEditMode, False, False) End If End If End SubEnd Class
C# version
using Infragistics.Win.UltraWinGrid;using System.Windows.Forms;using System;public class UltraGridUddMouseWheelHack{ private object mUddSavedValueForMouseWheelHack; public UltraGrid mUgrid; public void InigUltraGridUddMouseWheelHack() { this.mUgrid.ControlAdded += new ControlEventHandler(this.mUGrid_ControlAdded); } private void mUGrid_ControlAdded(object sender, ControlEventArgs e) { UltraGrid uGrid = (UltraGrid) sender; UltraDropDown udd = uGrid.ActiveCell.ValueListResolved as UltraDropDown; if (udd != null) { e.Control.MouseWheel += new MouseEventHandler(this.mUGrid_uddControl_MouseWheel); e.Control.KeyUp += new KeyEventHandler(this.mUGrid_uddControl_KeyUp); e.Control.Enter += new EventHandler(this.mUGrid_uddControl_Enter); udd.AfterCloseUp += new DropDownEventHandler(this.mUGrid_uddControl_AfterCloseUp); } } private void mUGrid_uddControl_AfterCloseUp(object sender, DropDownEventArgs e) { this.SaveUltraDropDownSelectedValue(); } private void mUGrid_uddControl_Enter(object sender, EventArgs e) { Control senderControl = (Control) sender; UltraGrid uGrid = senderControl.Parent as UltraGrid; if (uGrid != null) { UltraDropDown dropdown = uGrid.ActiveCell.ValueListResolved as UltraDropDown; if (dropdown != null) { this.mUddSavedValueForMouseWheelHack = uGrid.ActiveCell.Value; } } } private void mUGrid_uddControl_KeyUp(object sender, KeyEventArgs e) { this.SaveUltraDropDownSelectedValue(); } private void mUGrid_uddControl_MouseWheel(object sender, MouseEventArgs e) { Control conSender = (Control) sender; UltraGrid ugSender = (UltraGrid) conSender.Parent; if (ugSender != null) { UltraDropDown dropdown = ugSender.ActiveCell.ValueListResolved as UltraDropDown; if ((dropdown != null) && (!dropdown.IsDroppedDown)) { ugSender.ActiveCell.Value = this.mUddSavedValueForMouseWheelHack; ugSender.PerformAction(UltraGridAction.ExitEditMode, false, false); } } } private void SaveUltraDropDownSelectedValue() { if ((this.mUgrid.ActiveCell != null) && (this.mUgrid.ActiveCell.ValueListResolved != null)) { this.mUddSavedValueForMouseWheelHack = this.mUgrid.ActiveCell.ValueListResolved.GetValue(this.mUgrid.ActiveCell.ValueListResolved.SelectedItemIndex); } }}
Did you Submit a feature request to Infragistics?
dwolf81 said:Thanks for posting this, really helped me out. Instead of saving the orignal value and reseting it you can actually just do a UltraGrid1.ActiveCell.CancelUpdate().
No problem. I still hope that Infragistics at least gives us an option to do something like this standard.
I tried the CancelUpdate() thing, but that doesnt work quite the way I want it to. If the user selects a value from the drop down, and then scrolls down, it will revert back to the original value - not the one the user selected. I want it to stay on the value the user selected.
Thanks for posting this, really helped me out. Instead of saving the orignal value and reseting it you can actually just do a UltraGrid1.ActiveCell.CancelUpdate().
private object _dropdownValue;
Then I add a ControlAdded event (ugSender is an UltraGrid):
ugSender.ControlAdded += new ControlEventHandler(ugSender_ControlAdded);
In ControlAdded event, put the code:
void ugSender_ControlAdded(object sender, ControlEventArgs e)
{
string contType = sender.GetType().ToString();
UltraGrid ugSender = sender as UltraGrid;
UltraDropDown uddSender = ugSender.ActiveCell.ValueListResolved as UltraDropDown;
if (uddSender != null)
e.Control.MouseWheel += new MouseEventHandler(Control_MouseWheel);
e.Control.Enter += new EventHandler(Control_Enter);
uddSender.AfterCloseUp += new DropDownEventHandler(uddSender_AfterCloseUp);
}
The uddSender_AfterCloseUp event looks like this:
void uddSender_AfterCloseUp(object sender, DropDownEventArgs e)
UltraDropDown uddSender = sender as UltraDropDown;
_dropdownValue = _ultraGrid.ActiveCell.Value;
The Control_Enter event looks like this:
void Control_Enter(object sender, EventArgs e)
Control conSender = sender as Control;
UltraGrid ugSender = conSender.Parent as UltraGrid;
if (ugSender != null)
UltraDropDown dropdown = ugSender.ActiveCell.ValueListResolved as UltraDropDown;
if (dropdown != null)
And the Control_MouseWheel event looks like this:
void Control_MouseWheel(object sender, MouseEventArgs e)
_ultraGrid.ActiveCell.Value = _dropdownValue;
ugSender.PerformAction(UltraGridAction.ExitEditMode, false, false);
Whats happening here is:
A few points.
I havnt really accounted for the user selecting a value by other means. I'm assuming if the user selects a value by typing something in, they will tab or enter to select it, which will then move the focus to another field - so there is no real issue here (I think).
I havnt really tested this a great deal. As I said, I just worked out this solution last night, so only basic testing has been done so far. If you find ways to improve it, please post it back here!
--- EDIT ---
The Control_MouseWheel event needs a little additional code, so that both of the lines:
Are within another conditional statement
if (!dropdown.IsDroppedDown)
I did say I hadnt tested it much...