I'm trying to dynamically creating dropdownList
boxes, and I want trying to add AddHandlers
to them so that when an item is selected in them, it fires an event, but also need to pass another variable, and I don't know what to put as the parameter for system.EventArgs
. Please look at the code below to see the problem I'm having.
AddHandler inputDrop.SelectedIndexChanged, AddressOf selOption(inputDrop, ???, var1)
Protected Sub selOption(ByVal sender As Object, ByVal e As System.EventArgs, ByVal tableCount As String)
End Sub
What do I put (???) right here.
The error:
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
In addition what Mike C already explained, if the signature of the event handler does not match the event, you can always wrap the event handler in another method, for example an anonymous one:
Protected Sub selOption(ender As Object, e As System.EventArgs, somestring As String)
End Sub
...
For i = 1 To 10
Dim cbox = new ComboBox()
Dim number = i ' local copy to prevent capturing of i '
AddHandler cbox.SelectedIndexChanged, Sub(s, e) selOption(s, e, "Hi! I am Number " & number)
Next
Now, when the index of the last ComboBox
changes, the somestring
parameter passed to selOption
will be Hi! I am Number 10
, while it will be Hi! I am Number 1
for the first ComboBox
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With