c# - Add a datagridview column from another form -
i have 2 forms , datagridview in form1.im trying add new column clicking in button form2.like that:
form2 private void button1_click(object sender, eventargs e) { form1 form1 = new form1(); form1.datagridview1.columns.add("test" , "test"); }
how can that?
form1 form1 = new form1();
this not work real form1 there, pressume. instead create reference in form2 , load in form2's constructor!
here steps:
- the local reference form1 in form2's variables:
form1 form1
when opening form2 pass reference form1 in constructor:
form2 = new form2(this);
store in local refence in constructor on form2:
public form2(form1 form1_) { initializecomponent(); form1 = form1_; }
now set use form1 , public properties , controls. use form1.datagridview1
must make public first, though. (or create public reference it..)
Comments
Post a Comment