Checking for Radio buttons

  • Thread starter Thread starter Michael Hesse
  • Start date Start date
M

Michael Hesse

Hi,

I have an application with 177 radio buttons on a screen (Don't ask!). Is
there a simple want to excute a sub when any of them are checked.

Thanks,

Michael
 
Michael said:
I have an application with 177 radio buttons on a screen (Don't
ask!). Is there a simple want to excute a sub when any of them are
checked.

You could make your own radio button class that inherits from the standard
radio button and add a static event to the definition. Then, override the
onclick method, call the base method, and raise the event. you can then
handle this event like any other from your code.
 
Great suggestion. Thanks!

Michael
Leon Mayne said:
You could make your own radio button class that inherits from the standard
radio button and add a static event to the definition. Then, override the
onclick method, call the base method, and raise the event. you can then
handle this event like any other from your code.
 
Hello, Michael,

Perhaps you could iterate through the controls on your form, and for
those that are radio buttons, use AddHandler to assign the same routine
as the CheckedChanged handler for all of them. Something like:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
For Each ctl As Control In Me.Controls
If (TypeOf ctl Is RadioButton) Then
Dim rbt As RadioButton = DirectCast(ctl, RadioButton)
AddHandler rbt.CheckedChanged, _
AddressOf Common_CheckedChanged
End If
Next
End Sub

Private Sub Common_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim rbtSender As RadioButton = DirectCast(sender, RadioButton)
MsgBox(rbtSender.Name & " is now " & rbtSender.Checked)
End Sub

Cheers,
Randy
 
Back
Top