Click here to Skip to main content
15,913,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hell

how to passing values from to another without reinitialize form c#

this is what iam trying to do
C#
frm_employees emp_form = new frm_employees();
            emp_form.txt_empid.Text = txt_emp_code.Text;
            emp_form.Show();


this code reinitialize the form again i don't need this,so could you please help me with this.

thanks in advance

this image can make it clear
http://i.imgur.com/cFZL66t.jpg[^]

What I have tried:

C#
frm_employees emp_form = new frm_employees();
            emp_form.txt_empid.Text = txt_emp_code.Text;
            emp_form.Show();
Posted
Updated 16-Jul-16 19:54pm

refer this example

Child Form
C#
public partial class FormChildEmployee : Form
    {
        public frm_employees ParentFormObject { get; set; }  // create a property for parent form

        public FormChildEmployee()
        {
            InitializeComponent();
        }
         
        private void btnSelect_Click(object sender, EventArgs e)
        {
            ParentFormObject.txt_empid.Text = txt_emp_code.Text; // assign the child's textbox value to the parent form Textbox without creating new instance
        }
    }



in Parent Form

C#
// opening the child pop up on button click in parent form
private void btnOpenPopUpChild_Click(object sender, EventArgs e)
       {
           FormChildEmployee objChild = new FormChildEmployee();
           objChild.ParentFormObject = this; // initialise this object( parent form ) to the property created.
           objChild.Show();
       }


Note: make the Parent Form textbox (txt_empid) as Public modifier in the design view.
 
Share this answer
 
Your are trying to have a "child" form which passes data back to it's "parent"?
That's pretty simple - all you need is an event (and maybe a property).
See here: Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900