Add datagridview cell content into textbox in other form c# -
i have 2 forms. 1 have textbox show name of chosen customer , 1 have datagridview show list of customers. when click on textbox second form open. want know possible double click on datagridview cell text of textbox change datagridview selected cell on first form? here codes.
i wrote code open form2:
private void textbox1_click(object sender, eventargs e) { frmcustomer customer = new frmcustomer(); customer.showdialog(); }
and in form2 :
private void datagridview1_celldoubleclick(object sender,datagridviewcelleventargs e) { string name = datagridview1.currentrow.cells["clmname"].value.tostring(); form1 f = new form1(); f.txtcustomer.text = name; this.close(); }
there nothing in textbox when form2 closed.
any help? milion
you can try passing form1 parameter when creating form2.
private void textbox1_click(object sender, eventargs e) { frmcustomer customer = new frmcustomer(this); // represents form1 customer.showdialog(); }
then on form2
private form1 frm_1; public form2(form1 frm) { initializecomponent(); frm_1 = frm; } private void datagridview1_celldoubleclick(object sender,datagridviewcelleventargs e) { string name = datagridview1.currentrow.cells["clmname"].value.tostring(); frm_1.txtcustomer.text = name; this.close(); }
this work.
Comments
Post a Comment