Custom number sorting

3 posts, 0 answers
  1. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 25 Jan 2012 Link to this post

    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. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 26 Jan 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 27 Jan 2012 Link to this post

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