Keyboard navigation after programmatically selecting an item

3 posts, 0 answers
  1. Gil
    Gil avatar
    2 posts
    Member since:
    Apr 2013

    Posted 29 Oct 2015 Link to this post


    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;

    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. Milena
    Milena avatar
    227 posts

    Posted 02 Nov 2015 Link to this post

    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: 

    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;

    I hope this information helps.

    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
  3. Gil
    Gil avatar
    2 posts
    Member since:
    Apr 2013

    Posted 09 Nov 2015 Link to this post

    Worked great! thank you very much!

    only difference is that i used :

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

Back to Top