I am writing a desktop application using WPF and RadGridView. I need to be able to operate 100% of the application without a mouse (keyboard navigation to every aspect of the application).
Is it possible to access column headers via keyboard navigation? If so, how do you do it?
8 Answers, 1 is accepted
I am afraid that the control does not support utilizing all of its functionalities with the keyboard only. May I kindly ask you to share some details on the exact behavior you are aiming at?
In addition, you can take a look at the Keyboard Support topic.
Telerik by Progress
Thanks for the clarification.
We have already replied you in the support thread you opened regarding this requirement. In order to avoid double posting, I would kindly ask you to continue any further communication regarding this topic in the support thread.
Thanks in advance for understanding.
Telerik by Progress
I am pasting the reply of my colleague from the support thread for your reference as well attaching the sample application.
I prepared a basic project that illustrates how to modify RadGridView's tab navigation, which I am attaching to my post. The general idea behind it is cancelling the default navigation logic in certain occasions. To accomplish this, I am using a custom commands provider, clearing the default commands when a certain condition is met. Another important modification is the addition of a focusable border in the GridViewHeaderCell's template. It is named "FocusableSort", if you want to find it in the theme file.
The border is needed as the default template elements are not focusable. When the border gets focused, you will be able to execute sorting by processing its KeyDown event. A similar approach can be used for opening the filtering dropdown.
Hope this helps.
I've been working with the code provided in this post and noticed that the CustomProvider does not actually do anything. Access to the headers is solely achieved by via a Border with Focusable="True" on line 1568, but keyboard navigation gets trapped in the header with a Tab press. In the CustomProvider, the return pendingCommands line in the if (headerRow.Cells... block never gets called. Also, focusedCell is always null because the focusedElement, which must be a grid does not have a ParentOfType<GridViewHeaderCell>.
Some other questions:
The clubsGrid is not a focus scope yet a cell can retain logical focus as if the grid did act as a focus scope. Can you please explain the focus scopes related to the RadGridView?
The sample is very buggy. Could you provide another?
Something that is particularly interesting: if you use the following code, then you would expect no keyboard events to get fired, but with the sample code provided above, the header tabbing continues to work.
I verified that the visual tree has one and only one focus scope, the main window, by walking up the tree from each focused element.
When tabbing from the header to the data cells presenter, the CurrentCell property is advanced. This seems to be caused by the RadGridViewCommands.MoveNext command. The code in the zip file clears the commands when the last header cell has keyboard focus. How do you cancel the MoveNext command so the that CurrentCell property is not advanced? Clearing the pendingCommands does not work.
Thank you for the provided code snippet.
Firstly, please allow me to say that the project attached to my colleague's reply is not a fully implemented solution. It serves as a guideline on how the desired requirement can be implemented. That said, note that by default the RadGridView column headers cannot be navigated with the keyboard and a lot of customization is needed in order to achieve this functionality.
With the above information in mind, I will address your questions:
You are correct that the main customization is the addition of a Border inside the GridViewHeaderCell ControlTemplate. This Border has its Focusable property set to True. This allows for tabbing back and forward inside the header cells and is handled by native WPF logic. This is why tabbing through the headers works even after the "pendingCommands" are cleared.
As for the focus scopes, the RadGridView actually does not define any focus scopes inside it. In the context of the sample application, the focus scope variable is not necessary. It would be needed, if additional custom focus scopes are defined.
I am attaching an updated version of the sample project to serve as guidance on how the custom functionality can be implemented. The main idea is to handle the scenario when the border inside the last GridViewHeaderCell is focused and also when the first GridViewCell of the first row is focused. Feel free to tweak the approach in order to suit your exact scenario. Also, note that I have not tested the approach extensively and you should do so before including it in your application.
I hope you find this helpful.