简体   繁体   中英

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

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

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

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM