j2associates Posted April 27, 2006 Posted April 27, 2006 Hello all, I am using event handlers in a class I am writing and I want to add my own event hanldling if the control does not already have it. As an example, let's say I want to handle SelectedIndexChanged for a ComboBox if it is not currently trapping that event. How do I go about determining if a given ComboBox is already trapping SelectedIndexChanged? Thanks in advance for any ideas and/or suggestions! Quote
Cags Posted April 27, 2006 Posted April 27, 2006 I believe you can test to see if an event is hooked up using the following code. if(comboBox1.SelectedIndexChanged==null){} Quote Anybody looking for a graduate programmer (Midlands, England)?
j2associates Posted April 27, 2006 Author Posted April 27, 2006 Thanks, but I get an error when I try the equivalent VB.Net code. Quote
Leaders snarfblam Posted April 28, 2006 Leaders Posted April 28, 2006 VB event handling is a little different. In C#, events and delegates are treated exactly the same, where as VB has special syntax for events and hides the actual backing multicast delegate from the programmer. The VB RaiseEvent keyword automatically performs a check for null before invoking the delegate (in C# this must be done explicitly), but provides no mechanism to see if the event is wired as far as I know. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.