I have a lot of radio buttons in a groupbox. Normally I will check each radio button individually using If radiobutton1.Checked = True Then.
But I think
'returns which radio button is selected within GroupBox passed
Private Function WhatRadioIsSelected(ByVal grp As GroupBox) As String
Dim rbtn As RadioButton
Dim rbtnName As String = String.Empty
Try
Dim ctl As Control
For Each ctl In grp.Controls
If TypeOf ctl Is RadioButton Then
rbtn = DirectCast(ctl, RadioButton)
If rbtn.Checked Then
rbtnName = rbtn.Name
Exit For
End If
End If
Next
Catch ex As Exception
Dim stackframe As New Diagnostics.StackFrame(1)
Throw New Exception("An error occurred in routine, '" & stackframe.GetMethod.ReflectedType.Name & "." & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'." & Environment.NewLine & " Message was: '" & ex.Message & "'")
End Try
Return rbtnName
End Function