c# - Clicking a button on a DataGridView Cell Button triggers all the cell button commands in the row -


i have datagridview 9 columns. column index 4 , 8 cell buttons. when click on button index 4 execute command given execute command given button index 8. either way ever button click (4 or 8) execute action 1 action 2

private void dgvitems_cellcontentclick(object sender, datagridviewcelleventargs e) {     var sendergrid = (datagridview)sender;      if (sendergrid.columns[4] datagridviewbuttoncolumn && sendergrid.rows[e.rowindex] datagridviewrow)     {          messagebox.show("action 1: column index " + e.columnindex + "; row index " + e.rowindex);     }      if (sendergrid.columns[8] datagridviewbuttoncolumn && sendergrid.rows[e.rowindex] datagridviewrow)     {          messagebox.show("action 2: column index " + e.columnindex + "; row index " + e.rowindex);     } } 

just check current column e.columnindex. correct if condition as:

if (e.columnindex == 4)     messagebox.show("action 1: column index " + e.columnindex + "; row index " + e.rowindex);  if (e.columnindex == 8) .... 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -