Search code examples
c#icsharpcode

About ComboBox SelectedIndex?


I have a combobox and list of it was from separate strings declared on a class .

sample:
as
asd
asdf
asdfg
asdfg

Everytime when i run it, it always selects the last part of list of combobox instead of firstpart. It is selecting asdfg instead of as.My question is how to make the list to be selected from first, that is starting from as as the selected index for the combobox? (or always in accending mode when alphabetically arranged)? thanks in advance..


Solution

  • you can try by sort and reverse :

     private void Form1_Load(object sender, System.EventArgs e)
     {
       ArrayList list = ArrayList.Adapter(comboBox1.Items);
       list.Sort();
       // if you want to reverse
       list.Reverse();
       comboBox1.SelectedItem=0;
     }