组合框特定项目 c#

Combobox specific item c#

我的组合框中有很多项目 其中之一是名为“警报”的项目 我想让代码知道,当所选项目为“警报”时,它会启动一个事件 我使用 c# 和 visual studio 2019 winform

SelectedIndexChanged 事件添加到组合框。 您可以获得如下详细信息。

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox comboBox = (ComboBox)sender;
    int selectedIndex = comboBox.SelectedIndex;
    int selectedValue = (int)comboBox.SelectedValue;
    string selectedItem = (string) comboBox.SelectedItem;
}