ListControl with custom comparer

4 posts, 1 answers
  1. Franco
    Franco avatar
    27 posts
    Member since:
    Apr 2010

    Posted 01 Sep 2011 Link to this post

    Good afternoon.
    With the old RadListBox I could write code like this:
        _radListBox.Items.Sort(comparer)
    with my custom comparer. How can achive this with the new RadListControl?

    Thank you very much.
    Gianfranco
  2. Answer
    Peter
    Admin
    Peter avatar
    1148 posts

    Posted 02 Sep 2011 Link to this post

    Hi Franco,

    Thank you for writing.

    Sorting in RadListControl is controlled only via the SortStyle property. It supports ascending sort style, descending sort style and no sort style. Setting sorting through code looks like this:

    radListControl1.SortStyle = Telerik.WinControls.Enumerations.SortStyle.Ascending;

    So, if you want to use custom comparer method for sorting operation you should use this approach:

    List<RadListDataItem> sortList = new List<RadListDataItem>(radListControl1.Items);
    sortList.Sort(MyOwnComparer);
    radListControl1.Items.Clear();
    radListControl1.Items.AddRange(sortList);

    I hope this helps. Best wishes,
    Peter
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Eric
    Eric avatar
    7 posts
    Member since:
    May 2012

    Posted 05 Jul 2012 Link to this post

    Hi!!

    I'm following the suggestion here, and I created a custom IComparer to order the list as numbers. But I'm having some problems creating a list from the RadListControl.List Method. It always return for me a list of RadListDataItem, but all of them are returned as Nothing. I'm using VB language. Here is the piece of code:

    'my comparer:
    Dim myComparer As IComparer(Of RadListDataItem) = New RadListDataItemNumericComparer()
     
    'here it creates the list with the number of items I have, but all items are Nothing (the same as null in C#):
    Dim sortList As New List(Of RadListDataItem)(myRadList.Items)
     
    'so, it fails here, because I have a list of Nothing objects:
    sortList.Sort(myComparer)
    myRadList.Items.Clear()
    myRadList.Items.AddRange(sortList)

    How can I make it create a proper list of RadListDataItem? Could it be a bug at the RadListControl component?

    Thanks in advanced!
    Eric
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 09 Jul 2012 Link to this post

    Hello Eric,

    Thank you for writing.

    I was not able to reproduce the described issue. Having in mind the numerous scenarios possible with this control, it will be best if you send us a sample project that reproduces the issue. This will allow us to investigate it and provide you with proper support.

    I am looking forward to your reply.

    All the best,
    Peter
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top