Button in DataGridView with condition C# -


i want add button column in datagridview...but condtion : when color of row red, datagridview:

enter image description here

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:

enter image description here

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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -