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
}
}
Loading

Hirendra SisodiyaRank #258 · 9.8K reputationPosted Apr 16, 2010, 9:24 PM EDT
there is no need to pass datagridview object . you can send only its datasource..if you wantto show same data on form2's datagridview.
try this
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(dataGridView1.DataSource);
frm.Show();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(DataTable dt)
{
InitializeComponent();
this.dataGridView1.DataSource = dt;
// this.dataGridView1 = dataGridView; //Not Working
}
}
thanks
Please mark as answere if it helps
Hector Hugo Alpizar CesenaRank #5,573 · 294 reputationPosted Apr 17, 2010, 6:32 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 17, 2010, 11:26 AM EDT
Hector Hugo Alpizar CesenaRank #5,573 · 294 reputationPosted Apr 29, 2010, 9:29 AM EDT