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
1705
Spacebar not editing checkbox field after using arrow keys
posted

I have a grid of entirely boolean fields.  I'd like my user to be able to zip through and make changes with just the keyboard.  When they use <tab>, it switches to the next cell and the spacebar changes the checkbox fine, but if you use the arrow keys, you switch to the next cell but the spacebar does NOT toggle the checkbox.  How can I get it to work with either <tab> or the arrow keys?

  • 469350
    Suggested Answer
    Offline posted

    Hi,

    I wasn't sure what the difference was between the two methods, so I created a sample project to take a look at this and handled the BeforePerformAction event of the grid. When you tab, you get an action of NextCellByTab. When you arrow, you get NextCellInBand. So clearly, the difference is between these two actions.

    Next, I put in a Debug.Writeline to display the grid.CurrentState. I find that after I tab, then state looks like this:

    Cell, CellFirst, InEdit, IsCheckbox, Row

    But when I arrow, it looks like this:

    Cell, IsCheckbox, Row

    So the difference is that the grid is not in edit mode when you use the arrow keys.

    There are a number of ways you could change this. You could modify the KeyActionMappings in the grid, for example. But that's probably not the best way to go and it's a bit complicated. So what I would do is this:


            private void ultraGrid1_BeforePerformAction(object sender, Infragistics.Win.UltraWinGrid.BeforeUltraGridPerformActionEventArgs e)
            {
                UltraGrid grid = (UltraGrid)sender;

                // Disable the firing of this event to prevent recursion.
                grid.EventManager.SetEnabled(GridEventIds.BeforePerformAction, false);

                try
                {
                    switch (e.UltraGridAction)
                    {
                        case UltraGridAction.NextCellInBand:                       
                        case UltraGridAction.PrevCellInBand:                       
                        case UltraGridAction.BelowCell:                       
                        case UltraGridAction.AboveCell:

                            // Perform the intended action.
                            grid.PerformAction(e.UltraGridAction);

                            // Enter edit mode.
                            grid.PerformAction(UltraGridAction.EnterEditMode);

                            // Cancel the action, so the grid doesn't perform it again, since we
                            // already did it.
                            e.Cancel = true;
                            break;
                    }
                }
                finally
                {
                    // Re-enabled the event.
                    grid.EventManager.SetEnabled(GridEventIds.BeforePerformAction, true);
                }
            }