Programmatically adding event handler to array of radio buttons

Posted by gSaenz on Stack Overflow See other posts from Stack Overflow or by gSaenz
Published on 2012-12-16T05:01:22Z Indexed on 2012/12/16 5:03 UTC
Read the original article Hit count: 116

Filed under:
|

Trying to add event handlers to radio buttons that are created on user input, looking at this and this as examples.

However I get an error that answerOptions is not an event.

Create the radio buttons

Private answerOptions(n) As RadioButton
...    
Private Sub showQuestion(n As Integer)

For i = 0 To answerOptions.Length - 1
    answerOptions(i) = New RadioButton
    AddHandler answerOptions, AddressOf Me.Radios_Click
    With answerOptions(i)
        ' --------- SET TEXT, LOCATION ETC.
    End With
    Me.Controls.Add(answerOptions(i))
Next
End Sub

Planning on then handling events with

Private Sub Radios_Click(sender As Object, e As EventArgs) Handles answerOptions.checked

End Sub

I want things to happen when the radios are checked. Don't want to use checkboxes as I want to limit one selection at a time.

© Stack Overflow or respective owner

Related posts about visual-studio

Related posts about vb.net-2010