Check for Event Handlers in VB .NET


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Check for Event Handlers in VB .NET

  1. #1
    Join Date
    May 2008
    Posts
    9

    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!

  2. #2
    Join Date
    Jul 2004
    Posts
    81
    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  3. #3
    Join Date
    May 2008
    Posts
    9
    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!

  4. #4
    Join Date
    Jul 2004
    Posts
    81
    You are correct - the hidden 'Event' field only works for custom events.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  5. #5
    Join Date
    May 2008
    Posts
    9
    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.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote 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?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  7. #7
    Join Date
    May 2008
    Posts
    9
    Quote 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

  8. #8
    Join Date
    Jun 2004
    Posts
    93
    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

  1. MMFAN Retires
    By MMFAN in forum .NET
    Replies: 20
    Last Post: 09-23-2002, 12:54 AM
  2. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 01:43 AM
  3. YAG's status report - Feb 14, 2002
    By Seth Grossman [MSFT] in forum .NET
    Replies: 1
    Last Post: 02-15-2002, 01:35 AM
  4. A moderate view.
    By Paul Mc in forum .NET
    Replies: 214
    Last Post: 06-01-2001, 08:27 AM
  5. Russell Jones
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center