-
Check for Event Handlers in VB .NET
Hey folks.
I've checked high and low for the answer to this question.
In VB .NET 2.0, is there a way to determine if an object's event has a handler associated with it? I know in C# you can do:
Code:
if (Object.Event == null) {}
but I cannot find an equivalent in VB.
You may ask why. For some unknown reason, when dynamically adding/removing handlers, we have multiple times where the only way to make sure the handle is removed is to:
Code:
For i as Integer = 0 to 100
RemoveHandler...
Next
We don't know why. We've debugged and verified that we only use AddHandler once for that particular control/event.
Thanks in advance for any help you can provide!
-
This is one of the most obscure areas of VB syntax, but you can do it with:
If Object.EventEvent Is Nothing Then
*note the extra 'Event' after the event name.
-
Hey David,
Thanks for the help.
I tried:
Code:
If btnSave.ClickEvent Is Nothing
(Do Something)
End If
However, the compiler gives the blue scribbly line and says "'Click Event' is not a member of 'System.Windows.Forms.Button'."
Does this work for non-custom classes/objects?
Thanks again!
-
You are correct - the hidden 'Event' field only works for custom events.
-
That's a shame.
Thanks for the info. We're HOPING that perhaps the issue we're having with needing to remove the handler multiple times is related to the fact that it's an Infragistics control. It honestly doesn't seem to happen to standard controls.
Thanks for all your help.
-
 Originally Posted by DaleyKD
We're HOPING that perhaps the issue we're having with needing to remove the handler multiple times is related to the fact that it's an Infragistics control.
Have you checked Infragistics web site/support site to see if there is any info on this subject?
-
 Originally Posted by Hack
Have you checked Infragistics web site/support site to see if there is any info on this subject?
Hey Hack,
I have indeed attempted to searcch the "lack of support" that Infragistics calls their support/forums. Everytime I try to search for anything Infragistics, it's always a feeble and usually futile attempt. And usually, if you ask them a question in the forums, they don't have a correct answer. If you point out what might be a bug, they'll indicate that it should not be.
It's very sad, really.
Thanks again,
Kyle
-
If I had to guess how to do this, I would look at reflection.
Reflecting the current assembly may allow you to list the handlers that are registred for an event. I have not investigated if this is true, but its worth looking into.
Similar Threads
-
Replies: 20
Last Post: 09-22-2002, 11:54 PM
-
By Glen Kunene in forum Talk to the Editors
Replies: 17
Last Post: 03-23-2002, 01:43 AM
-
By Seth Grossman [MSFT] in forum .NET
Replies: 1
Last Post: 02-15-2002, 01:35 AM
-
Replies: 214
Last Post: 06-01-2001, 07:27 AM
-
By Bill Seddon in forum .NET
Replies: 85
Last Post: 02-01-2001, 03:49 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|