コンボボックスで特定のインデックスが選択されたときに C1ComboBox にデータを設定するには、次のように、SelectedIndexChanged イベントを使用します。
To write code in Visual Basic
C# コードのコピーPrivate Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) c1ComboBox2.Items.Clear() If c1ComboBox1.SelectedIndex.ToString() = "1" Then c1ComboBox2.Items.Add("You selected the second item.") Else c1ComboBox2.Items.Add("You did not select the second item.") End If End Sub
To write code in C#
C# コードのコピーprivate void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { c1ComboBox2.Items.Clear(); if (c1ComboBox1.SelectedIndex.ToString() == "1") { c1ComboBox2.Items.Add("You selected the second item."); } else { c1ComboBox2.Items.Add("You did not select the second item."); } }