Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have dynamically created a set of radiobuttons.The code is as below:
VB
Dim y As Integer = 10
       Dim sName As String = "test"


       For x As Integer = 1 To y

           myRB = New RadioButton()

           myRB.Location = New Point(10, y)

           myRB.Text = "Candy " & x
           myRB.Name = x

           Panel1.Controls.Add(myRB)
           y += 20
       Next


i want to record what the user select,but how should i refer these control?

please help
Posted

1 solution

Either store then when you create them in a list or array of RadioButtons (recommended) or you can find them via the Panel1.Controls array and iterate through:
VB
For Each c As Control In panel1.Controls
    Dim rb As RadioButton = TryCast(c, RadioButton)
    If rb IsNot Nothing Then
        If rb.Checked Then
            ' Handle checked button
            Exit For
        End If
    End If
Next

If you chose the second option, I would put a distinctive value into the Tag property, or you will have to check the Text to tell which one it is.
 
Share this answer
 
Comments
Wanlambok 5-Mar-11 5:49am    
thank a lot!!
OriginalGriff 5-Mar-11 7:10am    
Welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900