check if an event is hooked?

Hi experts

I have a BindingSource which has the event CurrentChanged.

Now have to hook/unhook this event dynamically in my code. This alone wouldn't be a problem.
But how can I check if the CurrentChanged event is hooked up?

I tried

if(this.MyBindingSource.CurrentChanged == null)


but this gives an error which says that I can use CurrentChanged only with += or -=
I'm using .NET 2.0, VS2008, WinForms

Who is Participating?
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
I tried your code and got the same exception (not with binding source but with normal button control)
i am assuming that the inbuilt microsoft controls dont allow you from checking whether the event has been subscribed to or not

in this case i will recommend you to use a variable holding how many events have been hooked to and when ever a new event is hooked the value will be incremented and vice versa
Not usre exactly but take a look at

Sample events:

this.Init += new EventHandler(Default3_Init); // to add
this.Init -= new EventHandler(Default3_Init); // to remove
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

you can further check
if (this.Init != null) { .. event is hooked }  else { event is not hooked .. }
ArikaelAuthor Commented:

your code gives me the same exception as noted in my question.
it seems that you can't check whether the event has been subscribed to or not (see ragi0017's post).

Until now I just "unhooked" my event before I hooked it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.