关于ComboBox SelectedIndex?

时间:2013-03-19 10:40:46

标签: c# icsharpcode

我有一个组合框,它的列表来自一个类上声明的单独字符串。

sample:
as
asd
asdf
asdfg
asdfg

每当我运行它时,它总是选择组合框列表的最后部分而不是第一部分。它正在选择asdfg而不是as。我的问题是如何从首先选择列表,即从as开始作为组合框的选定索引? (或按字母顺序排列时始终处于加入模式)?提前谢谢..

2 个答案:

答案 0 :(得分:1)

您可以在向ComboBox添加元素后手动将SelectedIndex设置为0.

因此你得到:

comboBox.Items.Add("as");
comboBox.Items.Add("asd");
comboBox.Items.Add("asdf");
comboBox.Items.Add("asdfg");
comboBox.SelectedIndex = 0;

答案 1 :(得分:0)

您可以尝试sortreverse

 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;
 }