在一个tabcontrol里面有三个页,tabPage1,tabPage2,tabPage3
其中tabPage1里面包含二个GroupBox1,GroupBox2,一个button1
GroupBox1里面有N个textbox
GroupBox2里面有N个textbox2
点button1清空tabpage1里面所有的text的内容。
button1的代码为:
            foreach (Control ctrl in this.tabPage1.Controls)
            {
                if (ctrl is TextBox)
                {
                    ctrl.Text = "";
                    ctrl.Enabled = false;
                }
            }
但text里的内容并没有被清空,为什么?而且好象返回的tabPage1.Controls.count的值也不对。
请各位帮忙!

解决方案 »

  1.   

    很明显 textbox 不在tabpage里 在groupbox里
      

  2.   

    foreach(Control ss in this.tabPage1.Controls)
                    if (ss is TextBox)
                    {
                        TextBox t = ss as TextBox;
                        t.Clear();
                    }
      

  3.   

    试下,GroupBox2一样处理
    foreach (Control ctrl in this.GroupBox1.Controls)//清空GroupBox1里的文本框值
    {
      if (ctrl is TextBox) 
                    { 
                        ctrl.Text = ""; 
                        ctrl.Enabled = false; 
                    } }
      

  4.   

    楼上说的有道理!
    foreach(Control ss in this.GroupBox1.Controls) 
                    if (ss is TextBox) 
                    { 
                        TextBox t = ss as TextBox; 
                        t.Clear(); 
                    }
      

  5.   


    foreach (Control gbcontrol in this.tabPage1.Controls)
                {
                    if (gbcontrol is GroupBox)
                    {
                        foreach (Control ctrl in gbcontrol.Controls)
                            if (ctrl is TextBox)
                                ctrl.Enabled = false;
                    }
                }
      

  6.   

                foreach (Control ctrl in this.groupBox1.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        ctrl.Text = "";
                        ctrl.Enabled = false;
                    }
                }             foreach (Control ctrl in this.groupBox2.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        ctrl.Text = "";
                        ctrl.Enabled = false;
                    }
                } 暂时没想出来更好的方法
      

  7.   

                foreach (Control ctrl in this.groupBox1.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        ctrl.Text = "";
                        ctrl.Enabled = false;
                    }
                }             foreach (Control ctrl in this.groupBox2.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        ctrl.Text = "";
                        ctrl.Enabled = true;
                    }
                }