C# 開発

【C#】ComboBox (2)

2025.01.24 ComboBox : 選択アイテムが変更されたことを知る

private void Form1_Load(object sender, EventArgs e)
{
    string[] s1 = { "NEC", "SONY", "DELL" };
    comboBox1.Items.AddRange(s1);
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
  listBox1.Items.Add(comboBox1.Text);
}

2025.01.24 ComboBox : 選択されているアイテムを取得する

private void button1_Click(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == -1) return;

    listBox1.Items.Add(comboBox1.Text);
    listBox1.Items.Add(comboBox1.SelectedItem.ToString());
}

-C# 開発