如何正确获取在groupbox中放置了多个radiobutton控件的值?  

解决方案 »

  1.   

    http://topic.csdn.net/u/20080604/18/13998d15-cbc0-496e-8437-860441460863.html
      

  2.   

    Dim ctl As ControlFor Each ctl In GroupBox1.Controls
      If ctl.GetType Is RadioButton1.GetType() Then
        If CType(ctl, RadioButton).Checked Then
          MsgBox(ctl.Name)
          Exit For
        End If
      End If
    Next
      

  3.   

     foreach (Control con in this.groupBox1 .Controls )
               {
                   RadioButton rb = con as RadioButton;
                   if (rb.Checked)
                   {
                      //获取RadioButton的Text
                       this.label1.Text = rb.Text;
                   }           }
      

  4.   

    [Quote=引用 1 楼 njw1028 的回复:]
    http://topic.csdn.net/u/20080604/18/13998d15-cbc0-496e-8437-860441460863.html
    [/Quote不是那个啊  我举例来说吧  在groupbox中有2个radiobutton控件 分别是 男 和 女 
    现在使用一个srting类型的变量来存储groupbox中所获得的radiobutton选择 即是男还是女 
      

  5.   

    不行啊 string getstr; 
                 foreach (Control con in this.groupBox1.Controls)
                {
                    RadioButton rb = con as RadioButton;
                    if (rb.Checked)
                    {
                        getstr = rb.Text;
                    }
                }
    getstr 是string变量 但是使用messagebox.show(getstr)所显示的根本没有内容啊 并且在选择了radiobutton以后 getstr的值还是null啊 
      

  6.   

     ok 谢了 已经解决了 原来是执行代码的位置错了 刚进入窗体就执行 那时还没有选中,所以就所有的checked都是false的