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

Search capability

9 Answers 120 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tushar Gupta
Top achievements
Rank 1
Tushar Gupta asked on 17 Apr 2010, 05:32 AM
I am binding RadTreeView using MVVM pattern, everyhting works fine. There is lot of data that we are rendering in the treeview, one requirement is to have a search capability. We want to have a textbox that could be used to enter keywords and only those nodes should be displayed in the treeview that matches the search criteria. This is functionality thats similar to  Express blend where user can enter the property name and then only those properties are visible that matches the criteria.
Any help would be highly appreciated.
Thanks

9 Answers, 1 is accepted

Sort by
0
Jim Daly
Top achievements
Rank 1
answered on 19 Apr 2010, 08:05 PM
I think what you would want is a property in your view model that is bound to your text box's Text property (with TwoWay binding). Each time you type into the TextBox, the setter of your property will be called. You can then use the setter's value to filter the collection that is bound to your RadTreeView using LINQ.

What you probably need is a property that stores the entire collection (so that you can keep it around in memory), and a second property that stores the 'filtered' version of the collection. You would then bind your RadTreeView to the property that references the filtered collection.

Of course, each time the filtered collection changes you would need to notify the UI that the collection has changed via some sort of property changed notification.
0
Tina Stancheva
Telerik team
answered on 21 Apr 2010, 06:09 PM
Hello Tushar Gupta,

I attached a sample project illustrating how you can search through the items of a data bound RadTreeView. When the entered keyword matches an item from the tree, the item is expanded and highlighted.

Please take a look at the project and let us know if it helps. However, if your scenario requires a different approach, can you elaborate on that and we will help you implement it.

Let us know how it goes.

Sincerely yours,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jim Daly
Top achievements
Rank 1
answered on 10 May 2010, 04:50 PM
In order to get that Blend-like behavior, you'll probably just have to modify the code to do the filtering on the KeyUp event (instead of a button click), and would need to use LINQ to filter out the records that don't match what's in the tree view's data.
0
Tina Stancheva
Telerik team
answered on 13 May 2010, 12:27 PM
Hello Jim Daly,

I am not sure that I fully understand you.
However, I am attaching an implementation of search-as-you-type  in the TreeView with prev/next support where the TreeView is databound.

The example is based on a converter which takes a flat list of items (like in your case I suppose) and builds the hierarchy of items as needed.

Please let me know if this works for you.
If it doesn't can you please elaborate on your issues?
Thank you in advance.

Greetings,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Scott McEachern
Top achievements
Rank 1
answered on 26 May 2010, 07:51 PM
Hello Tina,

I'm having an issue with the project you attached here. If you search for the string "IT" (read: capital "I", capital "T" the browser hangs and the cursor does not change. I'm assuming this is because IT are common letters in the list of departments.

Can you let me know why this is happening? Also, do you have a copy of this project in C# rather than VB.net?

Thanks,
- Aaron
0
Tina Stancheva
Telerik team
answered on 01 Jun 2010, 11:52 AM
Hello Scott McEachern,

Please accept my apology for the delayed response. There was a problem in the Generate() method in the FolderViewModel class. It is fixed now.

Can you please give it a try and let us know if it works for you or if you need more info.

Also I removed some of the projects from the solution so that you can use the TreeViewSearch project (which is in C#) as a start-up project.

I hope this will help.

Sincerely yours,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Nick
Top achievements
Rank 1
answered on 06 Oct 2010, 08:20 AM
Sorry for bring the old thread up again, but I have additional question.
I have exactly same objective as original author, search for items and show only them from the view model.

I am binding TreeView.ItemsSource to PagedCollectionView that wrapped around ObservableCollection<MyType> and it is working just fine (or at least the same way as binding to ObservableCollection itself)
On a text bound property change event I am using pagedCollectionView.Filter to filter out items. I can see that vollection view is filtered, but UI is not notified for some reasons and thus not updating. I tried to bind exact same thing to DataGrid and PagedCollectionView filtering works just fine there.

I also tried to remove item from PagedCollectionView during filtering and it is actually removing it from the tree view as well.

Any idea how to notify treeview about pagedCollectionView.Filter without re-binding?

Thanks,
Nick
0
Nick
Top achievements
Rank 1
answered on 06 Oct 2010, 05:59 PM
I should take my comment back :)  I found out that I had a typo in my xaml that was casuing this problem.

In fact, I found that using a PagedCollectionView for filtering TreeView is pretty convenient way of doing that.
0
Tina Stancheva
Telerik team
answered on 11 Oct 2010, 01:45 PM
Hello Nick,

I am glad that you got it working. Also, this is a demo that you may also find helpfull. It demonstrates how you can implement search, sorting and filtering to the RadTreeView.

Please let us know if you need more info.

Sincerely yours,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Tushar Gupta
Top achievements
Rank 1
Answers by
Jim Daly
Top achievements
Rank 1
Tina Stancheva
Telerik team
Scott McEachern
Top achievements
Rank 1
Nick
Top achievements
Rank 1
Share this question
or