Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Hooking Events to Private Members of User Controls

0.00/5 (No votes)
4 Feb 2010 1  
Say you need capture an event for a control in a User Control and you are not permitted to change the control itself.You can hook into control events, even for private controls with this code://In a Windows Form//Get the private control cboSomePrivateControl from the user control's...
Say you need capture an event for a control in a User Control and you are not permitted to change the control itself.

You can hook into control events, even for private controls with this code:

//In a Windows Form

//Get the private control cboSomePrivateControl from the user control's Control collection
ComboBox cbo = (customUserControl.Controls["cboSomePrivateControl"] as ComboBox);

//Hook  control change and assign a method
cbo.SelectedIndexChange += new EventHandler(cbo_SelectionChange);

...

//create the method to handle the change.
void cbo_SelectionChange(object sender, EventArgs e)
{

}


It's that easy.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here