Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Having issues with RemoveHandler for a User Control?

I have a User Control that contains two combobox controls. Each of these comboboxes has a SelectedIndexChanged Event defined. I don't wish to have these events executed when the Windows Form loads so I'm trying to use the RemoveHandler/AddHandler statements. However, in the definition of the RemoveHandler, I'm getting a design-time error. Please see screenshot.
screenshot.jpg
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

When using the code editor or the Form Designer to create an event method, as a security as well as a good design feature, event methods are declared Private by default. They can thus be manipulated only from inside the in which they are created them.

If the code in which you use Add/RemoveHandler is in the same project, change the Private modifier in front of the event declaration to Friend. That way it can be called from anywhere inside the same project.

If the code is not in the same project, then set the modifier as Public, which enables any project that has a reference to deal with the event method.
Avatar of BlakeMcKenna

ASKER

"If the code in which you use Add/RemoveHandler is in the same project, change the Private modifier in front of the event declaration to Friend. That way it can be called from anywhere inside the same project."

The Add/RemoveHandler statements are in the code-behind of the Form that the UC resides on. I'm assuming the Event to declare as Friend is in the UC?
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi James,

You actually triggered some thoughts and I was able to figure it out. I see what your saying about the .jpg. I looked into that and played around with it as well. I finally got it working!

Thanks!