C# 根据组合框c的选择,我的代码没有切换到所需的功能#

C# 根据组合框c的选择,我的代码没有切换到所需的功能#,c#,combobox,C#,Combobox,代码没有调用show_auto函数,即使我从下拉列表中选择了化学品,它始终调用show_水泥函数 private void gunaComboBox1_SelectedIndexChanged(object sender, EventArgs e) { ArrayList companyName = new ArrayList(); ArrayList Price = new ArrayList(); ArrayList category = new ArrayList(

代码没有调用show_auto函数,即使我从下拉列表中选择了化学品,它始终调用show_水泥函数

private void gunaComboBox1_SelectedIndexChanged(object sender, EventArgs e) {
    ArrayList companyName = new ArrayList();
    ArrayList Price = new ArrayList();
    ArrayList category = new ArrayList();

    String selected = this.gunaComboBox1.GetItemText(this.gunaComboBox1.SelectedItem);

    if (selected.Equals("CHEMICAL")) {
        show_auto(companyName, Price, selected);
    } else {

        show_cement(companyName, Price, "CEMENT");
    }
}

然后与“CHEMICAL”进行比较

在测试之前,是否设置了断点并检查了所选的
?组合框中的“CHEMICAL”一定拼写错误。确保大小写匹配,并且组合框中单词“CHEMICAL”的开头或结尾没有空格。我测试了这个,只要组合框中有“化学物质”,它就可以工作。@Jessechun你是对的,事实上,一开始是由于空间的“化学物质”导致条件失败。谢谢你的见解。很高兴你成功了!
String selected = gunaComboBox1.selecteditem.text;