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

How to filter TreeView

13 Answers 997 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
gans
Top achievements
Rank 1
gans asked on 19 Feb 2012, 05:43 PM
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. 



   



13 Answers, 1 is accepted

Sort by
0
gans
Top achievements
Rank 1
answered on 20 Feb 2012, 02:12 PM
Any Help from Telerik?
0
gans
Top achievements
Rank 1
answered on 20 Feb 2012, 09:26 PM
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?

0
Petar Mladenov
Telerik team
answered on 21 Feb 2012, 07:34 PM
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 >>
0
gans
Top achievements
Rank 1
answered on 21 Feb 2012, 07:41 PM
Thanks so much for the response. I am eagerly waiting for an example.
0
Petar Mladenov
Telerik team
answered on 22 Feb 2012, 07:23 PM
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 >>
0
Petar Mladenov
Telerik team
answered on 22 Feb 2012, 07:45 PM
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 >>
0
gans
Top achievements
Rank 1
answered on 22 Feb 2012, 11:58 PM
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?
0
Petar Mladenov
Telerik team
answered on 23 Feb 2012, 08:10 AM
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 >>
0
Wolfgang
Top achievements
Rank 1
answered on 19 Jan 2015, 11:34 AM
This bug is fixed. You can use the 'ItemVisibility' property to hide an element.
0
itai
Top achievements
Rank 1
answered on 28 Jul 2015, 10:29 AM

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.

0
Petar Mladenov
Telerik team
answered on 29 Jul 2015, 08:58 AM
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
0
itai
Top achievements
Rank 1
answered on 29 Jul 2015, 05:18 PM

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.

0
Petar Mladenov
Telerik team
answered on 30 Jul 2015, 08:51 AM
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
Tags
TreeView
Asked by
gans
Top achievements
Rank 1
Answers by
gans
Top achievements
Rank 1
Petar Mladenov
Telerik team
Wolfgang
Top achievements
Rank 1
itai
Top achievements
Rank 1
Share this question
or