sorting RadListBox

Thread is closed for posting
3 posts, 0 answers
  1. Pierre Alain
    Pierre Alain avatar
    20 posts
    Member since:
    Jun 2008

    Posted 21 Jan 2010 Link to this post


    I have a RadListBox that I fill with just some strings, like this



    RadListBoxItem item = new RadListBoxItem(str);  

    I want this ListBox to stay sorted, so I set


    listBox.Sorted = Telerik.WinControls.Enumerations.SortStyle.Ascending; 

    Yet, the string are not sorted. What am I missing?

    I tried listBox.Items.Sort. The string are sorted, but then selection is screwed up. Clicking the first item in the list will select the actual first item added to the list.

  2. Victor
    Victor avatar
    1358 posts

    Posted 22 Jan 2010 Link to this post

    Hello pacarrier,

    Please clarify what is the order of actions that you perform since I cannot reproduce the sorting issue you described. Do you first add items and then sort RadListBox or the other way around?

    If you sort before adding the items they will not be added in the sorted order. This means that you either need to sort again each time you add an item or use binary search to determine the place to insert items. Please note that we released an internal build after Q3 2009 SP1 which fixes some of the sorting issues reported by users. If you do not find the information above useful I suggest upgrading to the internal build. Please write again if you need further assistance.

    Sincerely yours,

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Pierre Alain
    Pierre Alain avatar
    20 posts
    Member since:
    Jun 2008

    Posted 22 Jan 2010 Link to this post

    OK, I found the problem.

    I was setting the Sorted property to Ascending in the designer and then clear and filling the listbox dynamically.

    foreach (string str in myStrings)  
      RadListBoxItem item = new RadListBoxItem();  
      item.Text = str;  

    Adding the following line after the loop did not help:

    listBox.Sorted = Telerik.WinControls.Enumerations.SortStyle.Ascending; 

    I had to first reset the sorting using:
    listbox.Sorted = Telerik.WinControls.Enumerations.SortStyle.None; 

    Thanks for your help.
Back to Top