none
Getting value from child form to parent form? RRS feed

  • Question

  • I have a form, having tab control. Forms directly open in tab control as tab page. when i want to get data from child form to parent form. It gave error on owner ship of the form. Now i have changed the ownership of the form but still i cant get the value from child form to parent form. 

    My Code is:

    when I opened the child form

     

    private void button11_Click(object sender, EventArgs e)       

    {           

    using (New_Category new_Category = new New_Category("ProductDefinition"))           

    {               

    new_Category.ShowDialog();           

    }                       

    }


    Now from this child form i want to retrieve the value to parent form. the code is given below:

    Product_Defination prod = new Product_Defination("","");
    Main_form main = new Main_form("", "");
    prod.Owner = main;
    prod.get_productid_notifyme(Product_id);

    Saturday, February 16, 2019 12:08 PM

Answers

  • Hello,

    To set the Owner for the child form pass in 'this'.

    e.g. 

    new_Category.ShowDialog(this);

    In the child form cast Owner as the main form and access controls.

    So if my main form is Form1 (in this case has a DataGridView) and I show Form2 we can use the following to access Form1's DataGridView.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by zul hayat Saturday, February 16, 2019 2:25 PM
    Saturday, February 16, 2019 1:16 PM
    Moderator