Home All Groups Group Topic Archive Search About

determine which radiobutton in a groupbox is checked?

Author
29 Jun 2006 7:00 PM
Rich
Hello,

I have a groupbox that contains 3 radiobuttons.  Is there a groupbox
property or some syntax that identifies which radiobutton is checked?  Or do
I have to loop?

For Each rad As RadioButton In grpBox1.Controls
   If rad.Checked.Equals(True) Then Console.WriteLine(rad.Name)
Next

vs

(pseudo code)
Console.WriteLine(grpBox1.Controls.Checked.Name)


Thanks,
Rich

Author
29 Jun 2006 7:13 PM
md
You can use

Select Case True
    Case rad1.checked
            ... do something
    Case rad2.checked
            ... do something
End Select

Matt

Show quoteHide quote
"Rich" <R***@discussions.microsoft.com> wrote in message
news:3B0241B6-3657-497A-8C25-93A7CA34830A@microsoft.com...
> Hello,
>
> I have a groupbox that contains 3 radiobuttons.  Is there a groupbox
> property or some syntax that identifies which radiobutton is checked?  Or
> do
> I have to loop?
>
> For Each rad As RadioButton In grpBox1.Controls
>   If rad.Checked.Equals(True) Then Console.WriteLine(rad.Name)
> Next
>
> vs
>
> (pseudo code)
> Console.WriteLine(grpBox1.Controls.Checked.Name)
>
>
> Thanks,
> Rich
Author
29 Jun 2006 11:22 PM
Herfried K. Wagner [MVP]
"Rich" <R***@discussions.microsoft.com> schrieb:
> I have a groupbox that contains 3 radiobuttons.  Is there a groupbox
> property or some syntax that identifies which radiobutton is checked?  Or
> do
> I have to loop?

Add a common event handler to all the radio buttons which belong to a group:

\\\
Private m_Group1SelectedRadioButton As RadioButton

Private Sub RadioButtonGroup1_CheckedChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
) Handles _
    RadioButton1.CheckedChanged, _
    RadioButton2.CheckedChanged, _
    RadioButton3.CheckedChanged

    Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
    If SourceControl.Checked Then
        m_Group1SelectedRadioButton = SourceControl
    End If
End Sub
///


--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>