How to pass the DataGridView object to other DataGridView object?

Apr 16 2010 7:16 PM

I have to forms, in the first form appers the data grid where I put the data inside. Then in that form I press a boton, and a second form appers with a DataGridView with the same info that I wrote on the first form.
I pass a DataGridview object on the second form constructor but, the info from the first gridview is not showing.
Form 1 source code
public
partial class Form1 : Form
{
   public Form1()
   {
      InitializeComponent();
   }
   private void button1_Click(object sender, EventArgs e)
   {
      new Form2(dataGridView1).Show();
   }
}
Form 2 source code
public
partial class Form2 : Form
{
   public Form2()
   {
   InitializeComponent();
   }
   public Form2(DataGridView dataGridView)
   {
   InitializeComponent();
   this.dataGridView1.DataSource = dataGridView.DataSource; //Not working
   this.dataGridView1 = dataGridView; //Not Working
   }

}

Answers (4)