Button in DataGridView with condition C# -
i want add button column in datagridview...but condtion : when color of row red, datagridview:
now, button in column 'check-out' work...with red row or white row...my code:
int row = (int)this.datagridview1.currentcell.owningrow.cells[0].value; if (messagebox.show("check-out?", "message de confirmation", messageboxbuttons.yesno) == dialogresult.yes) { messagebox.show("success!!"); }
for button work red row, try code :
if (datagridview1.selectedrows[0].defaultcellstyle.backcolor == color.red) { int row = (int)this.datagridview1.currentcell.owningrow.cells[0].value; if (messagebox.show("check-out?", "message de confirmation", messageboxbuttons.yesno) == dialogresult.yes) {messagebox.show("success!!"); }
i have error: index off limits. must not negative , must less size of collection. in line:
if (datagridview1.selectedrows[0].defaultcellstyle.backcolor == color.red)
error:
thanks,
i find correct answer: should modifie line :
if (datagridview1.selectedrows[0].defaultcellstyle.backcolor == color.red)
with :
if(datagridview1.currentrow.defaultcellstyle.backcolor==color.red)
so use datagridview.currentrow
Comments
Post a Comment