Search a self-referencing treeview

6 posts, 0 answers
  1. Craig
    Craig avatar
    112 posts
    Member since:
    Nov 2011

    Posted 22 Oct 2013 Link to this post

    Hi
    I've successfully followed the help section Bind RadTreeView to Self-Referencing Data and I have a working example.
    Now I want to implement a search mechanism but this is where I am stuck.

    I've extended my business object to implement the IPath interface as suggested in the Using GetItemByPath section of the Retrieving Checked Items help topic but where I set Parent in the self-referencing example I don't know.

    Any ideas please?
    Thanks
    Craig


  2. Craig
    Craig avatar
    112 posts
    Member since:
    Nov 2011

    Posted 22 Oct 2013 Link to this post

    I've managed to implement a CollectionChanged event handler in my view model which matches the new item's parent id with the id of the corresponding item in the collection and set the new item's Parent object to that. 

    private void MyTree_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
        {
            if ((e.NewItems[0] as TreeItem).PId != null) //if parent id is not null
            {
                ObservableCollection<TreeItem> o = sender as ObservableCollection<TreeItem>;
                TreeItem p = o.FirstOrDefault(x => x.Id == (e.NewItems[0] as TreeItem).PId); //find the matching parent item in the collection
                (e.NewItems[0] as IPath).Parent = p; //and set the item's parent to it so we can generate the full path to it later when searching
            }
        }
    }

    I've used the search technique as described in the Implement Search, Filter and Sort help topic. It works but it is slow. (I think I also read using GetItemByPath can be slow in some situations so this must be one). Is there a faster way?

    This is an extract from the help topic: 
    foreach (Product product in category.Products)
    {
        if (product.Name.ToLower().Contains(searchText))
        {
            RadTreeViewItem item = radTreeView.GetItemByPath(category.Path + "\\" + product.Path);
            item.BringIntoView();
            item.IsSelected = true;
            return;
        }
    }
  3. DevCraft banner
  4. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 25 Oct 2013 Link to this post

    Hi Craig,

     The negative side of the given search approach is that you have to traverse each hierarchy level - categories, products , then something else. Instead, I would like to suggest you another approach. List all tree data in AutoComplete or ComboBox. When you type in the autocomplete, the search will be faster and you will easily get the corresponding ViewModel. Once you have the ViewModel with its Path - you can invoke BringPathIntoView() of the RadTreeView. Actually we have such approach demonstrated in our OrgChart demo - expand the panel ont he right side and search and select person in the ComboBox. We believe such solution is faster and it is based on much cleaner code.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Craig
    Craig avatar
    112 posts
    Member since:
    Nov 2011

    Posted 25 Oct 2013 Link to this post

    Hi Petar,
    I tried the combobox approach using the OrgChart demo for guidance. In my case, the combobox is too unresponsive with the amount of data loaded. Also in my case, the BringPathIntoView() method does not result in the item being brought into view. The tree starts fully  collapsed due to the number of items.

    Regards
    Craig

  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Oct 2013 Link to this post

    Hello Craig,

     In order to improve performance , you can also try AutoCompleteBox. As for the RadTreeView - it should definitely work although it is initially collapsed. The BringPathIntoView() method ensures the generation and expanding of containers. Could you please double check your set up for bringing into View - proper Path, PathSeparator, TextSearch.TextPath properties. You can follow the given article for BringPathIntoView(). If this does not help, you can send us an isolated sample showing the issue with this method and we can take a look too.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Craig
    Craig avatar
    112 posts
    Member since:
    Nov 2011

    Posted 05 Nov 2013 Link to this post

    Hi Petar,
    AutoCompleteBox did greatly improve performance.

    I've opened support ticket 755150 for the failure of BringPathIntoView() method to function as expected in my case. I've attached a working project that demonstrates it.

    Regards
    Craig
Back to Top
DevCraft banner