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

Navigation in the TreeView using keyboard

1 Answer 34 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Todd Millett
Top achievements
Rank 1
Todd Millett asked on 14 Feb 2011, 08:40 AM
Can the user navigate the treeview using keyboard i.e suppose there are different nodes in the tree, and the user want to navigate to a certain folder, he should be able to type the first character of the folder and that folder should be focused. 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 16 Feb 2011, 04:54 PM
Hello Todd Millett,

Could you please examine the following demo and its source code. Basically, the functionality you need is implemented in this method:
private void SearchForText()
{
    if (!string.IsNullOrEmpty(searchTextBox.Text))
    {
        searchText = searchTextBox.Text.ToLower();
        foreach (System.Examples.Web.NorthwindModel.ExampleProduct product in context.ExampleProducts)
        {
            if (product.ProductNameLowerCase.Contains(searchText))
            {
                RadTreeViewItem item = radTreeView.GetItemByPath(product.Path);
                item.BringIntoView();
                item.IsSelected = true;
                return;
            }
        }
    }
Instead of Contains() method, you could use StartsWith(). Now  you use the KeyDown event of the RadTreeView and to get the Key`s value and to pass it to the Search Method.
You can check out this articles for more inf on BringIntoView methods and GetitemByPath method.
Hope this will fit in your scenario. Please do not hesitate to ask if you need further help.

Greetings,
Petar Mladenov
the Telerik team
Tags
TreeView
Asked by
Todd Millett
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or