c# - How to add row in datagridview from another form? -
i have 2 forms. form1 contains datagridview. second(form2) form contains textboxs. when click ok button in form2, values should added in datagridview new row. code trying use pass data,but neither showing error nor result.
form2
private void btnok_click(object sender, eventargs e) { form1.datagridview.rows.add("firstname", "lastname", "success", "userid", datetime.now.tostring()); }
put on form1
private void button1_click(object sender, eventargs e) { form2 f2 = new form2(this); f2.show(); }
put on form2
private form1 form1; public form2(form1 form1) { initializecomponent(); this.form1 = form1; } private void button1_click(object sender, eventargs e) { form1.datagridview1.columns.add("firstname", "first name"); form1.datagridview1.columns.add("lastname", "last name"); form1.datagridview1.columns.add("userid", "userid"); form1.datagridview1.columns.add("success", "success"); object[] row = new object[] {"1","product 1","1000",datetime.now.tostring()}; form1.datagridview1.rows.add(row); }
that should it
and datagridview modifier should public
Comments
Post a Comment