I have a very messy long items full of strings in a combobox, and it would be lovely to just sort it from a to z to make it easier to track. Is it possible?
See Question&Answers more detail:osI have a very messy long items full of strings in a combobox, and it would be lovely to just sort it from a to z to make it easier to track. Is it possible?
See Question&Answers more detail:osThere are two possible ways that I could think of:
Sorted
PropertyIf you're using WinForms, you can use ComboBox.Sorted = true;
OrderBy
If the data in your combo box comes from in a form of a list, use OrderBy to the List
of data you are going to put in the ComboBox
before setting it.
Here's an example:
var myList = new List<string>() {"q","w","e","r","t","y"};
var sorted = a.OrderBy(c => c).ToArray()
comboBox1.Items.AddRange(sorted);