Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
How to support arrow key in cell's drop down in ultragrid
posted

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?

 

Parents
  • 35
    Suggested Answer
    Offline posted

    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,

    true);

                                }

                               

    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;

                                }

                               

    break;

                           

    case Keys.Space:

                               

    if (Grid.ActiveCell != null

                                    && Grid.ActiveCell.Column.Style == Infragistics.Win.UltraWinGrid.

    ColumnStyle.DropDownList)

                                {

                                    Grid.PerformAction(

    UltraGridAction.ToggleDropdown);

                                }

                               

    break;

                       

    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))

                                    {

                                        e.Handled =

    true;

                                        DisplayFormulaEditor();

                                    }

                                }

                               

    catch (Exception ex)

                                {

                                    e.Handled =

    true;

                                   

    Info.ShowError(Logfile.MessageType.Error, sModule, ex, false, "Error handling key event.");

                                }

                               

    break;

                        }

Reply Children