Hendra Anggrian Hendra Anggrian - 1 year ago 159
C# Question

C# - is it possible to arrange ComboBox Items from a to z?

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?

Answer Source

There are two easy ways that I could think of:

  • If you're using Win Forms, just use ComboBox.Sorted = true;

  • If the data in your combo box comes from in a form of a list, just use OrderBy to the List of data you are going to put in the ComboBox before putting it.


        List<string> a = new List<string>()

        comboBox1.Items.AddRange(a.OrderBy(c => c).ToArray());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download