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

Items filter

3 Answers 84 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gts
Top achievements
Rank 1
Gts asked on 20 Dec 2013, 03:06 PM
Hi. I have this class
public class User
{
    public string ID{get;set;}
    public string Name {get;set;}
    public string Phone{get;set;}
}
 
public class UserTree
{
   public string GroupName{get;set;}
   public List<User> UserInGroup{get;set;}
}
//in code I do this
...
List<UserTree> _userList = new List<UserTree>();
....
myTreeView.ItemsSource = _userList;

In my page I have textbox and treeview.
I want enter some text in textbox and show in treeview only groups and user who contain entered text.
But I don't want create new List<UserTree> and change itemssource for my treeview
Can I do this?

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 25 Dec 2013, 01:51 PM
Hello Artem,

We understand your requirement. First we want to encourage you to use ObservableCollection<User> (OC) instead of List because OC is better in reordering scenarios (drag drop) and when you need the collection to be notified on Insert/Delete.

There are basically two ways to achieve filtering in the RadTreeView. The first and the more elegant is to filter your ViewModels - create new list from your start list by filtering it and pass it to the ItemsSource of the RadTreeView. Could you please elaborate more on the reasons you do not wish this approach ?

The other one is to hide particular RadTreeViiewItems instead of removing their ViewModels fromthe ItemsSource. You can hide the RadTreeViewItems by binding their Visibilitty / ItemVisibility properties to a boolean / Visibility property from your ViewModels (User)
         private bool isVisible;
 
      public bool IsVivible
      {
          get { return this.isVisible; }
          set
          {
              if (this.isVisible != value)
              {
                  this.isVisible = value;
                  this.OnPropertyChanged("IsVivible");
              }
          }
      }
public class User : Telerik.Windows.Controls.ViewModelBase
<Style targettype=RadTreeViewItem >
     <Setter property=ItemVisibility, Value= {Binding IsVivible, Converter ={StaticResource boolToVisConverter
 
in Resources: <telerik:BooleanToVisibilityConverter x:Key=boolToVisConverter />
ItemVisibility will perform better if your RadTreeView is virtualized.

We hope this will help you proceed further.

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
matteo
Top achievements
Rank 1
answered on 09 Jan 2014, 01:21 PM
Hello Petar!

So this means for toggling node visibility we don't need to use the workaround with ItemsPanel described here anymore? And this works with tree virtualization enabled too?

Thanks!

M

0
Petar Mladenov
Telerik team
answered on 13 Jan 2014, 08:13 AM
Hello Matteo,

Yes you can try the approach with binding the ItemVisibility. It does not work well only if you have RadTreeViewItems with different Heights.

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 >>
Tags
TreeView
Asked by
Gts
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
matteo
Top achievements
Rank 1
Share this question
or