c# - Change dataGridView Cell Formatting on button click (not on cell click) -
i coding hotel booking manager school project. need chceck if guest in hotel has checked in or chcecked out. if guest not chcecked in or chcecked out day writen in database, need change color of row, mark reservation needs atention.
i trying find solution change cell formatting on button click(for now, later scheduled task). know how change cell formatting while loading data datagridview.
i have been trying this
datagridview1.rows[(int)myreader["id"]].style.backcolor = system.drawing.color.lightpink;
but says there no style method, understand because method cellformatting class.
i write code in cellformatting class, can't call on button click because don't know write between () sender , e.
private void datagridview1_cellformatting(object sender, datagridviewcellformattingeventargs e)
you can use defaultcellstyle
property of datagridviewrow
set style row, example:
foreach (datagridviewrow row in datagridview1.rows) { //if criteria row.defaultcellstyle.backcolor = color.red; }
also can change style in suitable event, example can hanlde rowprepaint
, check criteria on row , change style:
private void datagridview1_rowprepaint(object sender, datagridviewrowprepainteventargs e) { //you can find row way: this.datagridview1.rows[e.rowindex] //then check criteria on cell values //then can set style row way: this.datagridview1.rows[e.rowindex].defaultcellstyle.backcolor = color.red; }
Comments
Post a Comment