I have two forms and a datagridview which is in the form1.Im trying to add a new column by clicking in a button from form2.Like that:
Form2
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.dataGridView1.Columns.Add("test" , "test");
}
How can I do that?
Pravesh Singh
18-Aug-2014Form1 form1 = new Form1();
This will not work as your real form1 is already there, I pressume. Instead create a reference to it in form2 and load it in form2's constructor!
Here are the steps:
the local reference to form1 in form2's variables: Form1 form1
When opening form2 pass a reference to form1 in the constructor:
form2 = new Form2(this);
Store it in the local refence in the constructor on form2: