I have a Windows Forms user control which consists of several controls. Among others there is also gridview control. Now I want to use the user control in a form. How can I check for example if a grid row is clicked? I want to get the data of the selected row. In other words, how can I detect events of the controls, which are embedded in the user control?
+1
A:
Create a new event on your user control and use it to expose the events of the gridview.
Gerrie Schenck
2010-10-04 13:28:47
+4
A:
You need to expose the events from your parent control by adding additional events:
public event EventHandler GridViewClicked;
And you call it on your child control using the following:
private void ChildControlGrid_RowClicked(object sender, EventArgs e)
{
if (GridViewClicked != null)
{
GridViewClicked(sender, e);
}
}
You then implement this the same way you would any event on your form:
yourControl.GridViewClicked += new EventHandler(ChildGridRowClicked);
private void ChildGridRowClicked(object sender, EventArgs e)
{
// Child row clicked
}
GenericTypeTea
2010-10-04 13:33:55