Davids Learning

I added a combobox dynamically to a tablelayout panel on a usercontrol.

I am wanting to change somethings when a user selects something within the combobox.

I tried this

Code Snippet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim T As New Combobox
Me.TableLayoutPanel1.Controls.Add(t,1,3)

T.SetBounds(50, 50, 200, 20)
AddHandler t.SelectedIndexChanged, AddressOf t_SelectedIndexChanged
End Sub


Private Sub t_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t.SelectedIndexChanged 'error is here at t

End Sub

Where did I mess up

Davids Learning



Re: Visual Basic Language Events from a dynamically created control

Andrej Tozon

Hi,

since you're adding event handler through your code, just remove the " Handles"part...

Code Snippet

Private Sub t_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Andrej