Click here to Skip to main content
15,915,867 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
How can I sort the listbox?

This is what I have found in the msdn, but it seems that I have to add a refrence to ?.Net
listBox2.Items.SortDescriptions.Add(new SortDescription(
                "Content", ListSortDirection.Descending));

Plese help.
Posted
Updated 8-Dec-10 10:44am
v3

IMO this is the wrong approach, the ListBox should be used for displaying data only. If the data should be shown sorted it should be sorted first then added to the control.

Add your items to a collection (List<T> maybe) and sort that however you wish then add the items to the ListBox.
 
Share this answer
 
What about ListBox.Sorted[^]?
 
Share this answer
 
You can either set the listbox property to true or you can get all the items of the listbox to an arraylist. With a foreach loop add them to the arraylist. Then sort the array. and add them sorted to the listbox again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900