Infragistics Ultragrid - do not move below row when selecting right most column

407 Views Asked by At

Is there any way to force Infragistics Ultragrid to do not move below row when pressing right arrow key on last column ?

eg having below table, being in cell with "C" value (COL_1, row 1) - if I press right arrow key it moves me to below row (D value), while I woudld like stay in same row, same cell (as Ive reached 'end' of row)

   COL_A | COL_B | COL_C
1    A      B        C
2    D      ...
2

There are 2 best solutions below

1
Jackdaw On BEST ANSWER

The KeyDown event for the UltraGrid might be used to implement this functionality too:

private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Right && sender is UltraGrid ug)
    {
        if ((ug.CurrentState & UltraGridState.CellLast) == UltraGridState.CellLast)
            e.Handled = true;
    }
}
1
wnvko On

Navigation in the grid is a result of default KyeActionMapping. What you can do is remove mapping for Right and add a new one preventing last cell state like this:

// Get the mappings related to Right key and remove them from KeyActionMappings
var mappings = this.ultraGrid1.KeyActionMappings.GetActionMappings(Keys.Right, 1, 0);
foreach (var mapping in mappings)
{
    this.ultraGrid1.KeyActionMappings.Remove(mapping);
}

// Add new KeyActionMappings
this.ultraGrid1.KeyActionMappings.Add(
    new GridKeyActionMapping(
        Keys.Right, 
        UltraGridAction.NextCell,
        UltraGridState.CellLast,
        UltraGridState.Cell,
        SpecialKeys.AltCtrl,
        0,
        true));