datagridview - How to display the selected rows of the grid view in another form using C# Form application? -


i want display data datagridview in second form text boxes in first form, when selected row double click event .

private void button1_click(object sender, eventargs e)         {             frm_drivers_list frm = new frm_drivers_list();             frm.showdialog();             id = convert.toint32(frm.dgv_driver.selectedrows[0].cells[0].value);             this.txt_code.text = frm.dgv_driver.selectedrows[0].cells[1].value.tostring();             this.txt_driver_name.text = frm.dgv_driver.selectedrows[0].cells[2].value.tostring();             this.txt_tel1.text = frm.dgv_driver.selectedrows[0].cells[3].value.tostring();             this.txt_tel2.text = frm.dgv_driver.selectedrows[0].cells[4].value.tostring();             this.txt_address.text = frm.dgv_driver.selectedrows[0].cells[5].value.tostring();             this.dtp_s_work.text = frm.dgv_driver.selectedrows[0].cells[6].value.tostring();             this.cb_workplace.text = frm.dgv_driver.selectedrows[0].cells[7].value.tostring();             this.cb_license_type.text = frm.dgv_driver.selectedrows[0].cells[8].value.tostring();             this.dtp_date_e_license.text = frm.dgv_driver.selectedrows[0].cells[9].value.tostring();             txt_code.readonly = true;             btn_edite.enabled = true;             btn_delete.enabled = true;             btn_add.enabled = false;         } 

this second form code have datagridview :-

public partial class frm_drivers_list : form     {         bl.cls_drivers clsdriver = new bl.cls_drivers();          int id;          public frm_drivers_list()         {             initializecomponent();             this.dgv_driver.datasource = clsdriver.get_all_drivers();             dgv_driver.columns[0].visible = false;         }           private void txt_search_textchanged(object sender, eventargs e)         {             datatable dt = new datatable();             dt = clsdriver.search_driver(txt_search.text);             this.dgv_driver.datasource = dt;         }          private void dgv_driver_doubleclick(object sender, eventargs e)         {             //frm_drivers frm = new frm_drivers();             //id = convert.toint32(this.dgv_driver.selectedrows[0].cells[0].value);             //frm.txt_code.text = this.dgv_driver.selectedrows[0].cells[1].value.tostring();             //frm.txt_driver_name.text = this.dgv_driver.selectedrows[0].cells[2].value.tostring();             //frm.txt_tel1.text = this.dgv_driver.selectedrows[0].cells[3].value.tostring();             //frm.txt_tel2.text = this.dgv_driver.selectedrows[0].cells[4].value.tostring();             //frm.txt_address.text = this.dgv_driver.selectedrows[0].cells[5].value.tostring();             //frm.dtp_s_work.text = this.dgv_driver.selectedrows[0].cells[6].value.tostring();             //frm.cb_workplace.text = this.dgv_driver.selectedrows[0].cells[7].value.tostring();             //frm.cb_license_type.text = this.dgv_driver.selectedrows[0].cells[8].value.tostring();             //frm.dtp_date_e_license.text = this.dgv_driver.selectedrows[0].cells[9].value.tostring();             this.close();         } 

this code work have problem , when close second form first row display in text box in first form want display when double click on row

form3 frm3 = new form3();             frm3.textbox7.text = datagridview1.currentrow.cells[0].value.tostring();             frm3.textbox6.text = datagridview1.currentrow.cells[1].value.tostring();             frm3.textbox2.text = datagridview1.currentrow.cells[2].value.tostring();             frm3.textbox9.text = datagridview1.currentrow.cells[3].value.tostring();             frm3.datetimepicker1.text = datagridview1.currentrow.cells[4].value.tostring();             frm3.textbox5.text = datagridview1.currentrow.cells[5].value.tostring();             frm3.textbox3.text = datagridview1.currentrow.cells[7].value.tostring(); 

to display particular cell in particular textbox on different form...this help


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -