我想顯示一定的值到一個標籤,取決於在comboBox中選擇的項目,comboBox中的每個項目將顯示不同的值,問題是組合框有很多項目和每個人都需要顯示不同的值C#更改標籤取決於組合框選擇索引
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox.SelectedIndex)
{
case 0:
if (comboBox.SelectedIndex == 0)
{
Label.Text = "8";
}
break;
case 1:
if (comboBox.SelectedIndex == 1)
{
Label.Text = "15";
}
break;
case 2:
if (comboBox.SelectedIndex == 2)
{
Label.Text = "60";
}
break;
}
}
我該如何改進並縮短它?我被告知要使用一個對象數組,但是如何驗證哪個項目被選中?
的事件代碼,謝謝!這種清單是我需要的,但我自己無法弄清楚 –
不客氣!您現在可以接受它作爲參考其他程序員的答案。 @RobertoMTorres –