When you register an event handler, you are not specifying arguments at this time. You basically just set up a link to the delegate who will handle the event when it is raised.
AddHandler inputDrop.SelectedIndexChanged, AddressOf selOption
Most importantly, the signature of the event handler method exactly matches the signature of the method defined by the event. I am not sure if your method will work because you have this extra parameter, tableCount
. You will need to change your method signature:
Protected Sub selOption(ByVal sender As Object, ByVal e As System.EventArgs)
I base this on the definition of SelectedIndexChanged
for Winforms. This event can be defined differently in another technology, such as ASP.net or WPF. Or, if it's some kind of custom class, it could be a completely different signature. However, usually most event handlers have a similar sender
structure (the instance that raises the event), and some event arguments.
Then, when inputDrop
fires this event (when the selected item changes), your code will be automatically called. The arguments passed to this method will be passed directly from inputDrop
, you do not need to specify them.
In addition, your AddHandler
must exist inside a method or code block; it cannot just live in a class definition. This is a statement that should be executed like any other piece of code, this is not a declaration.
source share