How to filter TreeView

14 posts, 0 answers
  1. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 19 Feb 2012 Link to this post

    Do you guys have a sample solution that does the filter on the Tree Generically. I have searched and all the examples are hard coded to filter couple of levels but they don't work if the tree has multiple levels.

    Could you please help me with a solution for this? I have tried using CollectionViewSource, but not able to filter below the Root level I am able to filter only at the top level. 

    Lets for example I have this Tree - got this from one of your examples. 

    Animal
      Dog
      Cat
    Fish
       Fresh Water
           Roach
           Bream
        Salt Water
            Skate
                  SkateChild
            Soul


    In this example, If I type  "d" , I should get the following result.
    Animal
        Dog
    Fish
        Salt Water 
             Skate
                  SkateChild

    Please let me know if you can help me with a solution that would work for n level of nodes. 

    This is highly critical for us and any help on this is really appreciated. 



       



  2. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 20 Feb 2012 Link to this post

    Any Help from Telerik?
  3. UI for WPF is Visual Studio 2017 Ready
  4. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 20 Feb 2012 Link to this post

    I am trying to achieve the filtering using the Visibility property of the RadTreeViewItem. I am Binding this to a property of my Entity and setting the Visibility based on the filtered text. 

    My ItemTemplate in the XAML looks like this. 

          <telerik:RadTreeView.ItemTemplate>
                                    <HierarchicalDataTemplate ItemsSource="{Binding Path=Folders}"  >
                                        <StackPanel Orientation="Horizontal" Margin="0" Tag="{Binding}" HorizontalAlignment="Stretch" 
                                                    Background="Transparent">
                                            <Image Source="D:\iApps\iEconomics\Dev\EOG.Economics.UIElements\Images\folder.png" Margin="0,1,0,0" Height="16" Width="16" />
                                            <TextBlock Text="{Binding Text}" Margin="5,1,0,0" />
                                        </StackPanel>
                                        <HierarchicalDataTemplate.Triggers>
                                            <DataTrigger Binding="{Binding Path=IsVisible}" Value="False">
                                                <Setter Property="Visibility"  Value="Collapsed"/>
                                            </DataTrigger>
                                        </HierarchicalDataTemplate.Triggers>
                                    </HierarchicalDataTemplate>
        </telerik:RadTreeView.ItemTemplate>

    The behaviour I am seeing with this is that, after Filtering it is showing the Nodes that did not match the criteria as Blank Nodes ie no name next to the Node. 

    I am attaching the screen  shot of what I am explaining. 

    Could you please help me out on this?

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Feb 2012 Link to this post

    Hi gans,

     The behavior you have come up with is expected. The defined HierarChicalDataTemplate defines the way the Header of the RadTreeViewItems will look like. When the Trigger is triggerred, the Header becomes Collapsed, but the CheckBox, Expander Toggle Button and other elements are not part of the Header and that is why they are not Collapsed. Unfortunately, collapsing the whole RadTreeViewItem is not possible which is previously logged in our PITS.
    We'll need some time in order to prepare a good filtering example in for the RadTreeView. We'll do our best to create one tomorrow and post it here. Thank you in advance for your patience.
     

    Regards,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 21 Feb 2012 Link to this post

    Thanks so much for the response. I am eagerly waiting for an example.
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Feb 2012 Link to this post

    Hi Ganesh,

     Attached you can find the promised example.

    Regards,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Feb 2012 Link to this post

    Hi Ganesh,

     I believe there was a mistake in the project I sent you. I modified it now to create a new Hierarchy when filtering. Tomorrow I will try to optimize it since the performance is not good enough.

    Kind regards,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 22 Feb 2012 Link to this post

    Thanks Petar for the example. If I am understanding right, you are creating new Collection of the Filtered ones and assigning that one as the ItemSource to the Tree right?
  10. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 23 Feb 2012 Link to this post

    Hello Gans,

     Yes, that's what I do. The performance is not quite good, but as I mentioned before , we cannot hide particular items - this is a bug in our RadTreeView logged here

    Regards,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  11. Wolfgang
    Wolfgang avatar
    8 posts
    Member since:
    Oct 2011

    Posted 19 Jan 2015 Link to this post

    This bug is fixed. You can use the 'ItemVisibility' property to hide an element.
  12. itai
    itai avatar
    6 posts
    Member since:
    Apr 2011

    Posted 28 Jul 2015 Link to this post

    Hi, I want to implement a filter mechanism, just like VS2013 has.

    However, as expected, the performance is poor. This is because when filtering, or when clearing the filters, the whole collection is being replaced, which makes the tree create all of the tree view items all over again.

    If using UIVirtualization (which is not enabled by default), the results are much better, however, UIVirtualization sucks in that manner. The scroll is not smooth (because new tree view items are being created while scrolling). Furthermore, the scroll size is not accurate, and it keeps increasing while scrolling, so this is out of the question!

     

    We have the 2012 controls, and I was expecting that this kind of problem will be fixed, and a feature like that would be out of the box (but it isn't).

     

    I want to implement it using Visibility, however, it appears that you didn't think it through!

    Although now the space is not reserved for the item is you change the ItemVisibility to collapsed, but this is why happens when you hide items.

    If last child is being hidden, then the previous child still has the vertical line continuing like it still exists.

    If all children are being hidden. then its parent still have the expander active... Look at the attached images.

  13. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Jul 2015 Link to this post

    Hi Itai,

    We highly encourage you to try newer release of UI for WPF -at least Q1 or Q2 2015. In 2014 we introduced some fixes in RadTreeView which increased the performance of the scrolling in RadTreeView.

    For the vertical lines, they are constructed by separate vertical lige segments which are part of every RadTreeViewItem's Control Template. There is no code responsible to cut the separate segment if the child items are hidden / collapsed. You can submit a feature request in our feedback portal and we will later review it and approve it.

    Similar is true for the Expander Icon, there is no code to listen for children visibility change to control the expander. However, you can add application . viewmodel logic to implement such kind of functionality.

    Regards,
    Petar Mladenov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  14. itai
    itai avatar
    6 posts
    Member since:
    Apr 2011

    Posted 29 Jul 2015 in reply to Petar Mladenov Link to this post

    I was assuming that the ItemVisibility would control both.

    The vertical line is being drawn by looking at the Position (Top middle or bottom), which is a getter property of the treeviewitem.

    I expected the position to take into account hidden items.

  15. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Jul 2015 Link to this post

    Hi Itai,

    The internal property Position is not designed to take into account child items' visibility. However this is valid for feature request. You can submit it in our feedback portal.

    Regards,
    Petar Mladenov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready