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

Custom number sorting

2 Answers 94 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
MiddleTommy
Top achievements
Rank 1
MiddleTommy asked on 26 Jan 2012, 05:38 AM
I am trying to find a way to have the TreeView sort the HierarchicalDataTemplate items. I can do this with a IValueConverter that changes the bound Items to a CollectionView with SortDescriptions however I need a custom sort. I want to sort strings Numerically

1A
2A
3A
10A
20A 

Normal sorting organizes these as

1A
10A
2A
20A
3A 

How can I get this custom sorting? I have an IComparer<string> that will provide the proper mechanism for the sorting but cant find where to plug it into.

2 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 26 Jan 2012, 02:56 PM
Hi Tommy,

I found couple of links that might be useful in your scenario:

How to achieve Natural(human alpha-numeric ) Sorting, for silverlight datagrids using ViewModel? 

Natural Sorting in C#

Take a look at them. In addition, please take a look at the attached sample which demonstrates one possible solution to your scenario. Let me know if you need further assistance.

Greetings,
Kiril Stanoev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
MiddleTommy
Top achievements
Rank 1
answered on 27 Jan 2012, 05:09 PM
I solved this by modifying a basic implementation of ICollectionView I found at
http://www.scottlogic.co.uk/blog/colin/2010/03/binding-a-silverlight-3-datagrid-to-dynamic-data-via-idictionary-updated/ 
Then in the HierarchicalDataTemplate I put a converter on the ItemsSource that wraps the bound items in a collection view.
Tags
TreeView
Asked by
MiddleTommy
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
MiddleTommy
Top achievements
Rank 1
Share this question
or