c# - How to Get comboBox value from a datagridview cell -
i want value of combobox
cell in datagridview
put in update method record. values combobox
displayed displaymember
, stored in database id
.
this combobox
in datagridview
in form load method combobox
cell @ index 15
............. dgv_cust.columns[14].name="web"; dgv_cust.columns[14].datapropertyname = "web"; datagridviewcomboboxcolumn cbcol = new datagridviewcomboboxcolumn(); cbcol.name = "accstatus"; cbcol.datapropertyname = "cbcol"; // datatable column name cbcol.items.add(new comborecord(0, "")); cbcol.items.add(new comborecord(1, "active")); cbcol.items.add(new comborecord(2, "notactive")); cbcol.items.add(new comborecord(3, "other")); cbcol.displaymember = "status"; cbcol.valuemember = "idx"; cbcol.displayindex = 15; dgv_cust.columns.add(cbcol); dgv_cust.columns[15].name = "accstatus"; dgv_cust.columns[15].datapropertyname = "accstatus"; dgv_cust.columncount = 17; dgv_cust.columns[16].name="location"; dgv_cust.columns[16].datapropertyname = "location"; dgv_cust.datasource = dbconn.getcustinfo1(); }
i getting values datagridview
pass update method this.....
private void button2_click(object sender, eventargs e) //updatecustomer { //here want valuemember(idx) cell[15], combobox string postalcode = this.dgv_cust.currentrow.cells[2].value.tostring(); string name = this.dgv_cust.currentrow.cells[3].value.tostring(); string businessname = this.dgv_cust.currentrow.cells[4].value.tostring(); string altname = this.dgv_cust.currentrow.cells[5].value.tostring(); string adrs1 = this.dgv_cust.currentrow.cells[6].value.tostring(); string adrs2 = this.dgv_cust.currentrow.cells[7].value.tostring(); string city = this.dgv_cust.currentrow.cells[8].value.tostring(); string province = this.dgv_cust.currentrow.cells[9].value.tostring(); string phone1 = this.dgv_cust.currentrow.cells[10].value.tostring(); string phone2 = this.dgv_cust.currentrow.cells[11].value.tostring(); string email1 = this.dgv_cust.currentrow.cells[12].value.tostring(); string email2 = this.dgv_cust.currentrow.cells[13].value.tostring(); string web = this.dgv_cust.currentrow.cells[14].value.tostring(); string location = this.dgv_cust.currentrow.cells[16].value.tostring(); try { dbconn.updatecustinfo1(accstatus, postalcode, name, businessname, altname, adrs1, adrs2, city, province, phone1, phone2, email1, email2, web, location); } catch (exception es) { messagebox.show(es.message); }
how valuemember(idx)
displaymember
("", "active", "notactive", "other") of combobox
in dgv
combobox
value stored 'idx
' in database.
i have similar project asp.net , use findcontrol find combobox id
guess using form, i'd try that:
combobox cbo = this.controls.find("combotbox1", true).firstordefault() combobox;
Comments
Post a Comment