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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With