Unplanned
Last Updated: 21 Apr 2023 07:34 by ADMIN
David
Created on: 21 Apr 2023 07:27
Category: GridView
Type: Bug Report
0
RadGridView: Arrow keys do not work as expected while Ctrl is down in multiple selection scenarios
In this case, the MultiSelect property is set to true and the SelectionMode is targeting CellSelect. In general, holding the Ctrl key and clicking a cell will select cells in different positions. However, if we hold the Ctrl key and use the Up/Down arrow key to change the current cell, the current cell won't be changed. Only Left/Right arrow keys are working as expected.
1 comment
ADMIN
Dinko | Tech Support Engineer
Posted on: 21 Apr 2023 07:34

Hi David,

Thank you for reporting this. This indeed is not working as expected. A possible solution here will be to manually handle this scenario. You can create a custom GridDataRowBehavior and override the ProcessKey method where you can move the current cell depending on the press arrow key.

public  class CustomGridRowBehavior : GridDataRowBehavior
{
    public override bool ProcessKey(KeyEventArgs keys)
    {
        if (keys.Control)
        {
            if (keys.KeyCode == Keys.Up)
            {
                var rowIndex = this.GridViewElement.CurrentCell.RowIndex;
                var columnIndex = this.GridViewElement.CurrentCell.ColumnIndex;

                int newRowIndex = rowIndex == 0 ? 0 : rowIndex - 1;
                this.GridControl.CurrentRow = this.GridControl.Rows[newRowIndex];
                this.GridControl.CurrentColumn = this.GridControl.Columns[columnIndex];
                return true;
            }
            if (keys.KeyCode == Keys.Down)
            {
                var rowIndex = this.GridViewElement.CurrentCell.RowIndex;
                var columnIndex = this.GridViewElement.CurrentCell.ColumnIndex;

                int newRowIndex = rowIndex == this.GridControl.Rows.Count-1 ? this.GridControl.Rows.Count-1 : rowIndex + 1;
                this.GridControl.CurrentRow = this.GridControl.Rows[newRowIndex];
                this.GridControl.CurrentColumn = this.GridControl.Columns[columnIndex];
                return true;
            }
            if (keys.KeyCode == Keys.Left)
            {
                var rowIndex = this.GridViewElement.CurrentCell.RowIndex;
                var columnIndex = this.GridViewElement.CurrentCell.ColumnIndex;

                int newColumnIndex = columnIndex == 0 ? 0 : columnIndex - 1;
                this.GridControl.CurrentRow = this.GridControl.Rows[rowIndex];
                this.GridControl.CurrentColumn = this.GridControl.Columns[newColumnIndex];
                return true;
            }
            if (keys.KeyCode == Keys.Right)
            {
                var rowIndex = this.GridViewElement.CurrentCell.RowIndex;
                var columnIndex = this.GridViewElement.CurrentCell.ColumnIndex;

                int newColumnIndex = columnIndex == this.GridControl.Columns.Count-1 ? this.GridControl.Columns.Count-1 : columnIndex + 1;
                this.GridControl.CurrentRow = this.GridControl.Rows[rowIndex];
                this.GridControl.CurrentColumn = this.GridControl.Columns[newColumnIndex];
                return true;
            }
        }
           
        return base.ProcessKey(keys);
    }
}

public RadForm1()
{
    InitializeComponent();

    //register the custom row  behavior
    BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
    gridBehavior.UnregisterBehavior(typeof(GridDataRowBehavior));
    gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridRowBehavior());

    BaseGridBehavior gridBehavior2 = radGridView2.GridBehavior as BaseGridBehavior;
    gridBehavior2.UnregisterBehavior(typeof(GridDataRowBehavior));
    gridBehavior2.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridRowBehavior());
}

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.