110,534
社区成员
发帖
与我相关
我的任务
分享
{
comboBox1.Items.Insert(0, new ComboBoxItem("0","请选择"));
comboBox1.Items.Insert(1, new ComboBoxItem("1","根目录"));
comboBox1.SelectedIndex = 1;
MessageBox.Show(comboBox1.SelectedItem.ToString());//根目录
MessageBox.Show(((ComboBoxItem)comboBox1.SelectedItem).Value);//1
}
internal class ComboBoxItem:Object
{
private string value;
private string text;
public ComboBoxItem(string _value, string _text)
{
value = _value;
text = _text;
}
public string Text
{
get { return text; }
}
public string Value
{
get { return value; }
}
public override string ToString()
{
return text;
}
}
ArrayList cbValues = new ArrayList();//定义到外面private ArrayList cbValues = new ArrayList();
this.comboBox1.Items.Insert(0, "");
cbValues.Insert(0, value0);