I'm trying some little test on dataGridView
Form1
Form2
Why does the datagridview doesnt get the datasource from another form?
But when i try to uncomment the code on form1 and comment out the form2.ShowDialog();(this time form2 will not show and ignore.)
the dataGridView respond and add the data on it.
Form1
C#:
namespace dataTableTest
{
public partial class Form1 : Form
{
//DataTable table = new DataTable();
public Form1()
{
InitializeComponent();
//table.Columns.Add("a");
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.ShowDialog();
// MessageBox.Show("Add");
// table.Rows.Add("AA");
// dataGridView1.DataSource = table;
}
}
}
C#:
namespace dataTableTest
{
public partial class Form2 : Form
{
DataTable table = new DataTable();
public Form2()
{
InitializeComponent();
table.Columns.Add("a");
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
table.Rows.Add("AA");
form1.dataGridView1.DataSource = table;
form1.dataGridView1.Refresh();
MessageBox.Show("Add");
this.Hide();
}
}
}
Why does the datagridview doesnt get the datasource from another form?
But when i try to uncomment the code on form1 and comment out the form2.ShowDialog();(this time form2 will not show and ignore.)
the dataGridView respond and add the data on it.