c# - Move data to next cell on click when repopulating a grid after update -
populate grid view , on cell click populate text box on cell click event like,
private void dgvcompany_cellclick(object sender, datagridviewcelleventargs e) { int = dgvcompany.selectedcells[0].rowindex; id = dgvcompany.rows[i].cells[0].value.tostring(); txtcompanyname.text = dgvcompany.rows[i].cells[1].value.tostring(); txtcontactname.text = dgvcompany.rows[i].cells[2].value.tostring(); txtcontactpersonphone.text = dgvcompany.rows[i].cells[3].value.tostring(); txtaddress.text = dgvcompany.rows[i].cells[4].value.tostring(); txtcity.text = dgvcompany.rows[i].cells[5].value.tostring(); txtphone.text = dgvcompany.rows[i].cells[6].value.tostring(); cbisactive.checked = convert.toboolean(dgvcompany.rows[i].cells[7].value); }
here id string variable after populating text box edit , save update , refill grid previous method like,
public void fillcompanyinfo() { datatable dtcompanyinfo = objfunctions.getcompanyinfo(); if(dtcompanyinfo.rows.count>0) { dgvcompany.datasource = dtcompanyinfo; if (this.dgvcompany.columns.count == 8) { datagridviewcheckboxcolumn checkcolumn = new datagridviewcheckboxcolumn(); checkcolumn.name = ""; checkcolumn.headertext = "select"; checkcolumn.width = 50; checkcolumn.readonly = false; checkcolumn.fillweight = 10; //if datagridview resized (on form resize) checkbox won't take much; value relative other columns' fill values\\ dgvcompany.columns.add(checkcolumn); } } }
here use if condition counting column 8 because each time add column select , after populating grid again when click on grid , cell click event fire result in error ,
on line ,
id = dgvcompany.rows[i].cells[0].value.tostring();
object reference not found because getting null on cell 0 while working fine before update on cell click , when use break point getting id on cells[1] , cell[0] null
i not understanding error
hopes suggestion
thanks
Comments
Post a Comment