Sorting Combobox Items Alphabetically

To sort a collection of items inside a combobox alphabetically, one way to do it would be to use the SortDescription class. For this, first you need to add the System.ComponentModel namespace. Then initialize a new SortDescription class in which you can tell by what and how to arrange the list. And finally simply add the class to the combobox you wish to be arranged. In case you want to arrange a simple combobox (only one thing to arrange it by) use the "Content" string when initializing the class as shown in the example bellow:

SortDescription sd = new SortDescription("Content", ListSortDirection.Ascending);
comboBox1.Items.SortDescriptions.Add(sd);

5 comments: