I am using ultragrid and once of the column display dropdown list.
oColumn.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Left;
oColumn.Header.Caption = objCol.HeaderText;
oColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
oColumn.ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.OnMouseEnter;
when dropdown list is is opened and item is selected using mouse and CellListSelect event gets fired. this is working fine.
Now I want to support keyboard up/down and enter keys.
Expeted behaviour: Arrow key should allows me to navigate through the list, until the right item is selected and commited using the Enter Key.
Currently, when I use arrow key next or previous item is selected and committed. I don't requied to press enter. how can i support above mentioned expected behavior?
In the grid's KeyDown event handler you can do something like this:
switch (e.KeyCode)
{
case Keys.F3:
if (LastSearchType == GridSearchType.FindCell && LastFoundCell != null)
FindValueInGrid(LastSearchTerm,
true);
}
else if (LastSearchType == GridSearchType.FindColumn && LastSearchMatch != null)
FindColumn(LastSearchTerm,
break;
case Keys.Up:
case Keys.Down:
if (Grid.ActiveCell != null
&& Grid.ActiveCell.IsInEditMode
&& Grid.ActiveCell.Column.Style == Infragistics.Win.UltraWinGrid.
ColumnStyle.DropDownList
&& Grid.ActiveCell.DroppedDown)
((
EditorWithCombo)Grid.ActiveCell.EditorResolved).ValueList.MoveNextItemPreviousItem(e.KeyCode == Keys.Up); //Would be nice if this didn't close the list...
Grid.PerformAction(
UltraGridAction.EnterEditModeAndDropdown);
e.Handled =
true;
case Keys.Space:
ColumnStyle.DropDownList)
UltraGridAction.ToggleDropdown);
default:
try
string c = KeyCodeToChar(e.KeyCode);
if (Grid.ActiveCell != null && Columns != null && Columns.Count > 0
&& Columns.ContainsKey(Grid.ActiveCell.Column.Key)
&& Columns[Grid.ActiveCell.Column.Key].UnBound
&& c.Length == 1
&&
Regex.IsMatch(c, @"[A-Z0-9_.,/';\\|[\]`\-*+]", RegexOptions.IgnoreCase))
DisplayFormulaEditor();
catch (Exception ex)
Info.ShowError(Logfile.MessageType.Error, sModule, ex, false, "Error handling key event.");
Eh, wish I could edit that last post - maybe this is more readable: In the grid's KeyDown event do something like (in a switch):
//Force navigation of ValueList editors.
&& Grid.ActiveCell.Column.Style == Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList
((EditorWithCombo)Grid.ActiveCell.EditorResolved).ValueList.MoveNextItemPreviousItem(e.KeyCode == Keys.Up); //Would be nice if this didn't close the list...
Grid.PerformAction(UltraGridAction.EnterEditModeAndDropdown);
e.Handled = true;
case Keys.Enter:
//Toggle drop down menu's
&& !(e.KeyCode == Keys.Enter && !Grid.ActiveCell.DroppedDown))
Grid.PerformAction(UltraGridAction.ToggleDropdown);
Thanks for shared code