Search capability

10 posts, 0 answers
  1. Tushar Gupta
    Tushar Gupta avatar
    4 posts
    Member since:
    Sep 2009

    Posted 17 Apr 2010 Link to this post

    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
  2. Jim Daly
    Jim Daly avatar
    13 posts
    Member since:
    Apr 2010

    Posted 19 Apr 2010 Link to this post

    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.
  3. DevCraft banner
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 Apr 2010 Link to this post

    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.
  5. Jim Daly
    Jim Daly avatar
    13 posts
    Member since:
    Apr 2010

    Posted 10 May 2010 Link to this post

    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.
  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 13 May 2010 Link to this post

    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.
  7. Scott McEachern
    Scott McEachern avatar
    11 posts
    Member since:
    Feb 2010

    Posted 26 May 2010 Link to this post

    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
  8. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 01 Jun 2010 Link to this post

    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.
  9. Nick
    Nick avatar
    17 posts
    Member since:
    Oct 2010

    Posted 06 Oct 2010 Link to this post

    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
  10. Nick
    Nick avatar
    17 posts
    Member since:
    Oct 2010

    Posted 06 Oct 2010 Link to this post

    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.
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Oct 2010 Link to this post

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