コンボボックスで特定の項目が選択されたときに C1ComboBox にデータを設定するには、次のように、SelectedItemChanged イベントを使用します。
Visual Basicでコードを書く場合
Visual Basic コードのコピーPrivate Sub comboBox1_SelectedItemChanged(sender As Object, e As EventArgs) c1ComboBox2.Items.Clear() If c1ComboBox1.SelectedItem.ToString() = "Pittsburgh" Then c1ComboBox2.Items.Add("Pittsburgh is known as the Steel City and the City of Bridges.") c1ComboBox2.Items.Add("Pittsburgh has 446 Bridges") Else c1ComboBox2.Items.Add("You did not select Pittsburgh.") End If End Sub
C#でコードを書く場合
C# コードのコピーprivate void comboBox1_SelectedItemChanged(object sender, EventArgs e) { c1ComboBox2.Items.Clear(); if (c1ComboBox1.SelectedItem.ToString() == "Pittsburgh") { c1ComboBox2.Items.Add("Pittsburgh is known as the Steel City and the City of Bridges."); c1ComboBox2.Items.Add("Pittsburgh has 446 Bridges"); }else{ c1ComboBox2.Items.Add("You did not select Pittsburgh."); } }
