New to Telerik UI for WinForms? Start a free 30-day trial
How to Move the Current Row with Arrow Keys while RadGridView is in Edit Mode
Updated over 6 months ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2023.2.718 | RadGridView for WinForms | Desislava Yordanova |
Description
When the editor in RadGridView is active, it is expected to handle the user's input. For example, when a spin editor is activated in a decimal column, pressing the up/down arrow keys increases/decreases the editor's value. If you want to skip handling the up/down arrows by the editor and move the current row in the respective direction, you can have a look at the following code snippet which result is illustrated below:

Solution
When the editor is initialized, we can handle the keyboard processing and execute custom logic when the up/down arrow keys are pressed. In addition, the default logic for increasing/decreasing the value in the spin editor should be restricted:
C#
public RadForm1()
{
InitializeComponent();
this.radGridView1.CellEditorInitialized += RadGridView_CellEditorInitialized;
}
private void RadGridView_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
var spinEditor = e.ActiveEditor as GridSpinEditor;
if (spinEditor != null)
{
var element = spinEditor.EditorElement as RadSpinEditorElement;
element.InterceptArrowKeys = false;
element.KeyDown -= element_KeyDown;
element.KeyDown += element_KeyDown;
}
}
private void element_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Down)
this.radGridView1.GridNavigator.SelectNextRow(1);
else if (e.KeyData == Keys.Up)
this.radGridView1.GridNavigator.SelectPreviousRow(1);
}