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
Hector Hugo Alpizar CesenaPosted Apr 29, 2010, 1:29 PM
Sam HobbsPosted Apr 17, 2010, 3:26 PM
Hector Hugo Alpizar CesenaPosted Apr 17, 2010, 10:32 AM
Hirendra SisodiyaPosted Apr 17, 2010, 1:24 AM
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