combobox1至2 selectedindex

时间:2013-07-26 12:33:50

标签: c# combobox

我在选择组合框时出现问题。基本上我想在我的文本框结果为1时禁用button1但是问题是当button1被禁用时我选择了另一个不会启用的选项。那还有另一种方法吗?下面只是展示编码的一部分。

    double[,] arr; 
    public Form1()
    {
            arr = new double[3, 3];
            for (int i = 0; i < 2; i++)
            {
                arr[0, 0] = 1;
                arr[0, 1] = 0.79;
                arr[0, 2] = 1.17;
                arr[1, 0] = 1.26;
                arr[1, 1] = 1;
                arr[1, 2] = 1.08;
                arr[2, 0] = 0.85;
                arr[2, 1] = 0.93;
                arr[2, 2] = 1;
            }
        void CreateArray()
        {
        if (comboBox1.SelectedIndex == -1 || comboBox2.SelectedIndex == -1)
            return;
        else if (comboBox1.SelectedIndex == 1 || comboBox2.SelectedIndex == 0)
        {
            button1.Enabled = false;
        }
        else if (comboBox1.SelectedIndex == 0 || comboBox2.SelectedIndex == 1)
        {
            button1.Enabled = false;
        }
        else if (comboBox1.SelectedIndex == 1 || comboBox2.SelectedIndex == 2)
        {
            button1.Enabled = false;
        }
        else
        {
            button1.Enabled = true;
        }

1 个答案:

答案 0 :(得分:2)

如果第二个组合框只有3个项目,那么您将永远无法到达将按钮重置为启用状态的最后一个else子句。

这是因为您使用了||逻辑OR运算符,只有三个项目,您将始终在最终的其他

之前采用else if条件之一
相关问题