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

sorting RadListBox

2 Answers 264 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pierre Alain
Top achievements
Rank 1
Pierre Alain asked on 21 Jan 2010, 05:58 PM
Hi,

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

 

 

RadListBoxItem item = new RadListBoxItem(str);  
listBox.Items.Add(item); 

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 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 22 Jan 2010, 10:24 AM
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,

Victor
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.
0
Pierre Alain
Top achievements
Rank 1
answered on 22 Jan 2010, 01:41 PM
OK, I found the problem.

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

listBox.Items.Clear();  
 
foreach (string str in myStrings)  
{  
  RadListBoxItem item = new RadListBoxItem();  
  item.Text = str;  
  listBox.Items.Add(item);  

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.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Pierre Alain
Top achievements
Rank 1
Answers by
Victor
Telerik team
Pierre Alain
Top achievements
Rank 1
Share this question
or