[3.0/LINQ] Send data from child to parent. Code Check
Hello,
VS 2008
I have a parent and child form. The parent will open the child form and the user will click on a button. This will set a link label property in the parent form. I am just wondering if there is a more object oriented way of doing this. The code below is short and simple, but just interested to know if there is some better and more reusable if I need to make any changes.
My code in the parent form.
Code:
//Display all the missed calls
private void lnkMissedCalls_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MissedCalls frmMissedCalls = new MissedCalls();
frmMissedCalls.ResetMissedCalls(new EventHandler(this.OnResetAttempted));
frmMissedCalls.Show();
}
//Listen for when the clear list button is clicked in the child form and reset the label
public void OnResetAttempted(object sender, System.EventArgs e)
{
this.lnkMissedCalls.Visible = false;
}
Code in the child form
Code:
//Create an event that the main form can listen to. Reset the label in the parent
//form when the button is clicked in the child form.
public void ResetMissedCalls(EventHandler _eventHandler)
{
this.btnClearCallList.Click += _eventHandler;
}
Many thanks for any advice
Re: [3.0/LINQ] Send data from child to parent. Code Check
I would suggest that the child form handle its Button's Click event and then raise an event of its own. The parent form can then handle the child form's event directly.
You might also want to declare your own custom EventArgs class so you can pass a flag to the event handler.