Hi,
I've a form frmMain.cs, in which I've added a UserControl ucTest.cs. In the usercontrol, I've added a button click event, in which I'm populating a DataSet ds.
Now I need this dataset to be used on the frmMain.cs for manipulation. How do I pass the dataset ds which was updated in the click event of UserControl back to the frmMain.cs ?
I tried declare a delegate (i'm totally new to delegates) in the UserControl for this, as below --
public delegate Boolean EventHandler(object sender, EventArgs args, DataSet ds);
public event EventHandler evntExecute = delegate {};
In the frmMain.cs, I've added a EventHandler function as below --
public Boolean evntExecute_Handler(object sender, EventArgs e, DataSet ds)
{
// code using the Dataset ds values
}
Now how do I exactly subscribe this event in the frmMain.cs ?
Thanks.
Loading
Sam HobbsPosted Nov 16, 2011, 2:17 AM
sasikumarPosted Nov 16, 2011, 1:42 AM
Thanks for the response. I just wanted to know if there is a way to pass back additional parameters to the handler in the way specified in my earlier post.
Tried different options but couldn't find any. Finally, I had to stick with the original option of making it as a public member and using it in the calling form. That worked. Thanks.
Sam HobbsPosted Nov 11, 2011, 12:59 PM
So your delegate can be declared as:
public ClickedEvent Clicked = null;
Then call it from the UserControl click event as:
Clicked();
Note that you should check to see if it has been provided a value, so that is why we check for null. Then in your form:
And:
{
}