问题如下:
    我在TabControl中建了两个选项卡,选项卡1里有个comoboBox1,选项卡2里有个comoboBox2,我想问的是如果选择了comoboBox1下拉菜单中的一个后,能否让选项卡2里的comoboBox2下拉菜单不可选,同样如果选了后一个那么前一个不可选??
    照这种想法,有什么控件可以代替?(最好两个comoboBox是不可以动的)

解决方案 »

  1.   

    你要让两个互斥,选了一个既然另一个已经不能用了怎么互斥?
    意思是只能选一个?
    你想把这东西当radioButton用呢么.
      

  2.   

    定义两个全局bool bo1;bool=bo2;
    然后comoboBox 的选择事件里面改变bool的状态。也就是comoboBox1选中了则bo2设置为true
    剩下的呢自己写
      

  3.   


     foreach (Control con in this.tabPage1.Controls)
                {
                     //判断tabPage1里面的下拉框是否可以用如果可用
                        foreach (Control con in this.tabPage2.Controls)
                      {
                          //将tabPage2中下拉框设为不可以
                       }
                        //esle就可用
                }
      

  4.   

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.comboBox1.SelectedIndex != 0)
        {
            this.comboBox2.Enabled = false;
            this.comboBox2.SelectedIndex = 0;
        }
        else
        {
            this.comboBox2.Enabled = true;
        }
    }private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.comboBox2.SelectedIndex != 0)
        {
            this.comboBox1.Enabled = false;
            this.comboBox1.SelectedIndex = 0;
        }
        else
        {
            this.comboBox1.Enabled = true;
        }
    }
    大概这个意思把,SelectedIndex 最好改成SelectedValue
      

  5.   


     foreach (Control con in this.tabPage1.Controls)
                {
                    if (con is ComboBox)
                    {
                        if (((ComboBox)con).Enabled != false)
                        {
                            foreach (Control ctl in this.tabPage2.Controls)
                            {
                                ((ComboBox)ctl).Enabled = false;
                            }
                        }
                        else
                        {
                            foreach (Control ctl in this.tabPage2.Controls)
                            {
                                ((ComboBox)ctl).Enabled = true;
                            }
                        }
                    }
                }
    //测试通过--! 怎么不能实现
      

  6.   

    我问你的就是选了一个,另一个既然不能用了(Enable=false),那么你不是只能选这一次么.
    怎么可能实现向radioButton的效果.
      

  7.   

    --!!! 写在两个下拉框的chang事件里面--!!!!!!!!!!
    测试通过了 下班了 无聊
      

  8.   

     private bool bo1 ;
            private bool bo2;
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                bo2 = true;
            }
            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                bo1= true;
            }
            private void tabControl1_Click(object sender, EventArgs e)
            {
                switch (tabControl1.SelectedTab.Name)
                {
                    case"tabPage1":
                       if (bo1)
                        {
                            comboBox1.Enabled = false;
                        }
                        else
                        {
                            comboBox1.Enabled = true;
                            bo2 = false;
                            comboBox2.SelectedIndex = -1;
                        }
                        break;
                    case "tabPage2":
                        if (bo2)
                        {
                            comboBox2.Enabled = false;
                        }
                        else
                        {
                            comboBox2.Enabled = true;
                            bo1 = false;
                            comboBox1.SelectedIndex = -1;
                        }
                        break;
                }
            }
    感觉不是太好。你可以优化下