Items filter

4 posts, 0 answers
  1. Gts
    Gts avatar
    17 posts
    Member since:
    Jul 2012

    Posted 20 Dec 2013 Link to this post

    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?
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 25 Dec 2013 Link to this post

    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 >>
  3. DevCraft banner
  4. matteo
    matteo avatar
    3 posts
    Member since:
    Nov 2006

    Posted 09 Jan 2014 Link to this post

    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

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 13 Jan 2014 Link to this post

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