This is a migrated thread and some comments may be shown as answers.

Keyboard navigation after programmatically selecting an item

2 Answers 271 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gil
Top achievements
Rank 1
Gil asked on 29 Oct 2015, 11:49 AM

Hi

i have a treeview control in a wpf form

the user wants to jump and select an item when he presses any letter on the keyboard

so i did just that with the treeView_TextInput event and on capturing text i found the desired item and selected it like this:

treeView.SelectedItem = found;
treeView.BringItemIntoView(found);
treeView.BringIntoView();​

My problem is that after the item is selected, the keyboard navigation will not work from the newly selected item.

as a matter of fact, the navigation will move from the previously selected item that the user selected with the mouse and not from the one the code selected

is that a bug?

thank you

 ​

2 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 02 Nov 2015, 01:09 PM
Hi Gil,

Thank you for the code-snippet and the detailed explanation. 

Actually, when you select an item in code, the focus is not changed (as if you do the same using the mouse or the keyboard). In your scenario you can set the focus to the selected item using Focus method: 
selectedItem.Focus();

If your scenario is MVVM, then you should get the item container first and then set the focus. In this case you can use GetItemByPath method which calls internally BringItemIntoView and the same code fragment could be: 
var found = tree.GetItemByPath(path);
tree.SelectedItem= found;
found.Focus();

I hope this information helps.

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Gil
Top achievements
Rank 1
answered on 09 Nov 2015, 11:46 AM

Worked great! thank you very much!

only difference is that i used :

var treeItem = treeView.ContainerFromItemRecursive(found);​
 
treeItem​.Focus();
Since i bind the the tree to objects and it is easier to get the TreeItem that way 

Tags
TreeView
Asked by
Gil
Top achievements
Rank 1
Answers by
Milena
Telerik team
Gil
Top achievements
Rank 1
Share this question
or