在vs 2010中,用c#语言。我使用了combobox控件,里面有三项内容,分别是学生、老师、家长。

2025-02-23 19:36:30
推荐回答(3个)
回答1:

/*
* comboBox1.SelectedIndex 属性保存着comboBox1 的当前选中项的编号,
* -1为未选中项目,0为选中第一项,1为第二项,以此类推
*/
if(comboBox1.SelectedIndex == 0)
{
//代码块,自己写想要的功能吧
}
else if(comboBox1.SelectedIndex == 1)
{
//代码块,自己写想要的功能吧
}
else if(comboBox1.SelectedIndex == 2)
{
//代码块,自己写想要的功能吧
}

回答2:

switch(combobox.selectedItem.tostring())
{
case "" :
……
}

回答3:

string strSelected=combobox1.selectedText;
if(strSelected=="选择1")
{
操作1
}
else if(strSelected=="选择2")
{
操作2
}
else(strSelected=="选择3")
{
操作3
}