Stack Exchange
How to acces checked status of dynamicaly created Radio Buttons in VB
I create a variable amount of radio buttons in a Tab Page by reading the lines out of an array using:
Public Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim rbgen As RadioButton
    Dim tab1 = 0
    For y As Integer = 0 To Array.GetUpperBound(0) Step 1
        If Array(y, 0) = "ABC" Then
            rbgen = New RadioButton
            rbgen.Name = "RButton" & Convert.ToString(y)
            rbgen.Left = 10
            rbgen.Top = ((tab1) * 30)
            rbgen.Text = Array(y, 2)
            rbgen.Size = New System.Drawing.Size(260, 40)
            TabPage1.Controls.Add(rbgen)
            tab1 = tab1 + 1
        End If
    Next 
End Sub

When i click a "start" Button i need to run different code depending on the checked RadioButton. But how do i access the information of which radio Button is checked? 
Thank you very much for your help!

Can you loop through your controls checking for a checked radio button. Exit the loop at that point and compare the text, perhaps in a Select Case to determine what code to run next.

Thank you for your fast answer!
I tried it this way but it didnt work:
For Each TypeOfControl As Control In Controls |
For Each ChildType As Control In TypeOfControl.Controls |
If TypeOf ChildType Is RadioButton Then |
Dim StateOfRadioButton As RadioButton = DirectCast(ChildType, RadioButton)Then....
do you know why?

You could try to add a Handler after you add the radio button:
AddHandler rbgen.CheckedChanged, AddressOf RadioBox_CheckedChanged

and then you need to add this sub
Private Sub RadioBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim RadioBox As RadioButton = TryCast(sender, RadioButton)

If RadioBox IsNot Nothing Then

    MessageBox.Show(RadioBox.CheckState)

End If

End Sub

and if you want to check the status
For Each RadioBox In TabPage1.Controls.OfType(Of RadioButton)()
if Ctype(TabPage1.controls("RadioButton" & i), radiobutton).checked = true then
 'your Code Here
end if
next

I could not test it yet but I hope I already helped you a little bit :)

Thank you very much! You helped me a lot and your code worked nice!
Just one more problem. If i change the tab the last radio Button chosen in another tab is still active/selected. how can i change this?
