Generic event handlers possible? Accept "e As EventArgs" when event passes something more specific?

S

Samuel R. Neff

Is there any way to create a generic event handler that can be
subscribed to any event? If I have a sub..

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

and subscribe it to

AddHandler dataTable.ColumnChanged, AddressOf SomethingChanged

it gives me this error

Method 'Private Sub DataTable_SomethingChanged(sender As Object, e As
System.EventArgs)' does not have the same signature as delegate
'Delegate Sub DataColumnChangeEventHandler(sender As Object, e As
System.Data.DataColumnChangeEventArgs)'.


Even though the signature doesn't match exactly, it is still
compatible. If it wasn't a delegate but just a regular method call I
could pass an instance of DataColumnChangeEventArgs to a variable
expecting EventArgs. But that appears no to be the case with
delegates.

Any work-around? What I want to do is have one function that listens
to several events and at this point it seems I need a separate
function for each since they need different signatures (I don't care
about the details at all, I just want to know the event was
triggered).

Thanks,

Sam


B-Line is now hiring one VB.NET developer for
WinForms + WebServices position with ASPX in future.
Seaking mid to senior level developer. For
information or to apply e-mail sam_blinex_com.
 
M

Mattias Sjögren

Is there any way to create a generic event handler that can be
subscribed to any event?

In v1.x, no. In v2.0 the runtime supports it, but I'm not sure VB.NET
will.

Any work-around?

Create multiple event handlers that all call a common method.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top