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
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
;
}
}
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
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 >>
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
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
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 >>
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