.net - Capture single row in a datagridview -
i have .net windows app.
i have datagridview
has few rows in it. had added column containing buttons allow user edit row. pops new form/dialog - edit form.
// add cellclick handler handle clicks in button column. dgv.cellclick += new datagridviewcelleventhandler(dgv_cellclick);
the code fires is:
private void dgv_cellclick(object sender, datagridviewcelleventargs e) { if (e.columnindex == buttoncell) { // id number int number = convert.toint32(dgv.rows[e.rowindex].cells[0].value); editform edit = new editform(number); edit.showdialog(); } }
problem
my edit form displays (correctly). make changes, , close form. loads again! same number of rows in grid. ie. fires code above once each row in datagrid.
how can prevent this? there more elegant solution?
i make sure you're not registering cellclick
event more once.
i.e., you're not calling code more once (like each time add row dgv):
dgv.cellclick += new datagridviewcelleventhandler(dgv_cellclick);
Comments
Post a Comment