Click here to Skip to main content

Hooking Events to Private Members of User Controls

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...
Sign Up to vote bad good
Add a reason or comment to your vote: x
Votes of 3 or less require a comment
See more: C#WinForm
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.
Posted 4 Feb '10
Edited 4 Feb '10


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Your Filters
Interested
Ignored
     
  1. Christian Graus (1,119)
  2. SAKryukov (602)
  3. CRDave1988 (322)
  1. SAKryukov (10,433)
  2. Christian Graus (7,113)
  3. OriginalGriff (5,166)
  4. Abhinav S (4,550)
  5. thatraja (4,376)

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --

Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 4 Feb 2010
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid