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

Sorting

1 Answer 170 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 26 Jun 2013, 02:07 PM
I have tried everything I can think of and I can not get the nodes in my RadTreeView sorted alphabetically. I am using Hierarchical data binding and my tree is heterogeneous, but all of the objects have a Name property which is what I want to sort on. The most promising approach seemed to be using a CollectionViewSource but this is not working (note the tree view and all children show up fine, just not sorted).

The XAML for my CollectionViewSource is

<CollectionViewSource x:Key="ManagerView">
    <CollectionViewSource.SortDescriptions>
        <cm:SortDescription Direction="Ascending" PropertyName="Name"/>
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource>

My RadTreeView is

<telerik:RadTreeView x:Name="ManagerTreeView" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Source={StaticResource ManagerView}}"/>

And the code behind to connect the CollectionViewSource to my data is 

CollectionViewSource cvs = this.TopLevelGrid.Resources["ManagerView"] as CollectionViewSource;
cvs.Source = RemoteWorkspace.Instance.RemoteManager;

Note that the tree shows up, all the objects are there, they are simply not sorted.

I have resorted to sorting the collections in my application code, but this seems less desirable.

Is there a way to sort the items in a RadTreeView that uses data binding.

Also note that all of my data is stored in ObservableCollections because the content is dynamic (i.e. RemoteWorkspace.Instance.RemoteManager refers to an ObservableCollection). Not sure if this makes a difference or not.

Thanks
Dave

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 01 Jul 2013, 10:18 AM
Hi David,

Our RadTreeView control is designed to display large amount of hierarchical data and it does not support sorting, filtering and searching out of the box. In order to achieve such functionality you have to apply there operations on the ItemsSource collection of the RadTreeView control. The CollectionViewSource can do the the sorting and filtering.

However, as I can't be sure about your implementation I can not make suggestion about our scenario. Basically the ItemsSource of the RadTreeView control can be set to a CollectionViewSource and the sorting functionality works as expected.

Please take a look at the attached project and see if it works for you. If you still can reproduce your issue, please change the project so that the issue can be reproduced in it and sent it over. By doing this we will be able to fully understand your scenario and make a suggestion after further investigation.

Thank you for your kind cooperation.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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
David
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or