Results 1 to 2 of 2

Thread: [3.0/LINQ] Send data from child to parent. Code Check

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    [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
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width