determine which radiobutton in a groupbox is checked?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
You can use

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

Matt
 
Rich said:
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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top