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

Search a self-referencing treeview

5 Answers 68 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 22 Oct 2013, 10:52 AM
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


5 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 22 Oct 2013, 12:58 PM
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;
    }
}
0
Petar Mladenov
Telerik team
answered on 25 Oct 2013, 08:07 AM
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 >>
0
Craig
Top achievements
Rank 1
answered on 25 Oct 2013, 09:49 AM
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

0
Petar Mladenov
Telerik team
answered on 30 Oct 2013, 11:29 AM
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 >>
0
Craig
Top achievements
Rank 1
answered on 05 Nov 2013, 03:30 PM
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
Tags
TreeView
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or