Navigation in the TreeView using keyboard

2 posts, 0 answers
  1. Todd Millett
    Todd Millett avatar
    115 posts
    Member since:
    Jul 2009

    Posted 14 Feb 2011 Link to this post

    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. 
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 16 Feb 2011 Link to this post

    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
  3. DevCraft banner
Back to Top