Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i pass the datagridview from form2 to form1 datagridview control in column sno , productname,qty using c# .net 2010 (i need only in windows application because iam developing the project in windows application ) please help me step by step to do it sir...
Posted
Comments
ZurdoDev 18-Jun-14 14:18pm    
This does not make any sense. Can you explain more clearly?

Don't even try to pass controls between forms.
Instead, create a class holding the information and pass a Collection (such as a List<T>) of that class.

If you are trying to display a single row on the "new" form, then that's even easier: just create a constructor which takes teh appropriate parameters and pass them when you construct the instance.

If you are trying to pass information from a "child" form to it's "parent" then that's also pretty easy: Transferring information between two forms, Part 2: Child to Parent[^] will explain.
 
Share this answer
 
You would normally never send a DataGridView to anything at all. Controls are for displaying data, not for storing data or passing between methods calls.

You transfer the Data only. What you pass and how you pass it depends on what you're doing.
 
Share this answer
 
the solution is when you open Form2 pass Form1 as a parameter to the constructor of Form2 then you will have all the public controls there.

C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 ff = new Form2(this);
            ff.Show();
        }
    }



C#
public partial class Form2 : Form
   {
       private Form1 form1;
       public Form2(Form1 frm1)
       {
           form1 = frm1;
           InitializeComponent();
       }

       private void Form2_Load(object sender, EventArgs e)
       {
           MessageBox.Show(form1.button1.Text);
       }
   }


let say in this example button1 in Form1 is public ,so you have access to it in form2.

but you'd better to make public only whatever you need
 
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