checking if any radio buttons are checked

  • Thread starter Thread starter Remi Lillelien
  • Start date Start date
R

Remi Lillelien

Hello all,

Given I have a GroupBox named grpChoices, within this box i have 8
radiobuttons, named rbtButton1 through rbtButton8.
Now I would like to have a button btnOK which is enabled=false as long as
none of the radiobuttons in grpChoices are checked, and enabled=true when
the user checks one of the radiobuttons.

does anyone have an idea on how to do this, I have seached the documentation
but still no luck (then again I'm not a lucky guy)


thanks

Remi
 
You could do it like this (you have to add the 8 radbuttons)

Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles rbtButton1 .CheckedChanged,
rbtButton8.CheckedChanged
Dim rad As RadioButton
btnOK.Enabled = False
For Each rad In grpChoices.Controls
If rad.Checked Then
btnOK.Enabled = True
End If
Next
End Sub

or if the button stays true after you selected something

Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles rbtButton1 .CheckedChanged,
rbtButton8.CheckedChanged
btnOK.Enabled = True

End Sub
 
Remi -

One option would be to put this code in all the radio buttons check
changed event (remembering to change the index of the radio button):



If RadioButton1.Checked = True Then
Button1.Enabled = True
Else
Button1.Enabled = False
End If
 
Back
Top