Tab Navigation in RadGridView

1 Answer 127 Views
GridView
Premkumar
Top achievements
Rank 1
Iron
Iron
Premkumar asked on 27 Sep 2023, 04:44 AM
Hello Telerik Team,

I'm using RadGridView and having 40+ coulmns in it, out of which almost 20 columns are editable.

It means I'm having controls inside CellTemplate to select or to enter the data.

I want to jump to each control on pressing Tab key.

If I set IsTabStop="False" for the RadGridView, then it jumps as expected. But, I'm not able to jump to the hidden columns behind horizontal scrollbar due to column virtualization is enabled and hence it jumps to the next row.

If I disable the column virtualization, it jumps to the hidden column's control, but horizontal scrollbar is not moving correspondingly.

If I remove the IsTabStop property for the RadGridView and by setting TabStopMode="Skip" for the non editable columns, it jumps to the editable columns correctly and the scrollbar is also moving corresponding to the focus. But, it is not directly focusing on the controls inside CellTemplate, instead it focuses on the Cells on pressing Tab key. I need to press one more time to focus on the control.

Is there any possible way to focus on the control instead of Cell, and the scrollbar also moves correspondingly when the virtualization is on.

Please advise.

Note:
When I tried by setting Column Virtualization off, the performance is very poor as it has more number of columns and rows.


Thanks and Regards,
Muhammad Azhar Shah
Premkumar
Top achievements
Rank 1
Iron
Iron
commented on 09 Oct 2023, 06:46 AM

Hi Telerik Team,
I would like you to provide some solution on the above question.
Awaiting for your reply.

 

Thanks and Regards,
Muhammad Azhar Shah

1 Answer, 1 is accepted

Sort by
0
Accepted
Stenly
Telerik team
answered on 09 Oct 2023, 02:38 PM

Hello Premkumar,

To achieve this requirement, you can create a custom keyboard command provider and utilize the CurrentCell property of the RadGridView element inside the overridden ProvideCommandsForKey method. On the CurrentCell property, you could retrieve the editor element via its Content property and call the Focus method on it. However, this logic would have to be delayed a bit, in order for the CurrentCell property to not be null. It can be placed in the BeginInvoke method of the Dispatcher object.

The following code snippet shows the above suggestion's implementation:

public class CustomKeyboardCommandProvider : DefaultKeyboardCommandProvider
{
    private GridViewDataControl parentGrid;

    public CustomKeyboardCommandProvider(GridViewDataControl grid)
     : base(grid)
    {
        this.parentGrid = grid;
    }

    public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
    {
        List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();

        if (key == Key.Tab)
        {
            commandsToExecute.Clear();

            if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
            {
                commandsToExecute.Add(RadGridViewCommands.MovePrevious);
            }
            else
            {
                commandsToExecute.Add(RadGridViewCommands.MoveNext);
            }

            commandsToExecute.Add(RadGridViewCommands.SelectCurrentUnit);

            this.parentGrid.Dispatcher.BeginInvoke((Action)(() =>
            {
                if (this.parentGrid.CurrentCell != null)
                {
                    ((TextBox)this.parentGrid.CurrentCell.Content).Focus();
                }
            }));
        }

        return commandsToExecute;
    }
}

I have also attached a sample project for you to test.

Regards,
Stenly
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.

Premkumar
Top achievements
Rank 1
Iron
Iron
commented on 11 Oct 2023, 12:13 PM

Hi Stenly,

It's perfectly working. Thank you for the support.

 

Thanks and Regards,
Muhammad Azhar Shah

Tags
GridView
Asked by
Premkumar
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or