我试图根据我在组合框中选择的内容更改表单中的标签。 如果有人帮忙,它就行不通。
这是我的代码:
private void cmbItems_SelectionChangeCommitted(object sender, EventArgs e)
{
int index = cmbItems.SelectedIndex;
if (index == 1 && index == 2)
{
lblAmount.Text = "Weight in gram";
}
}
答案 0 :(得分:2)
if (index == 1 && index == 2)
{
lblAmount.Text = "Weight in gram";
}
使用||相反...索引不能同时为1 AND 2 .. 也可能是你没有选择1是kg,2是克..如果是这样的话,yoy可以使用开关:
switch(index)
{
case 1:
lblAmount.Text = "Weight in Kg"; break;
case 2:
lblAmount.Text = "Weight in Grams";
break;
default:
lblAmount.Text = "Weight in Grams";
}