c# - How to colorize current cell only in DataGridView -


the code have got colorizing cells of row need colorize certain/current cell.

how can done?

private void datagridview1_cellpainting(object sender, datagridviewcellpaintingeventargs e)         {             if (e.rowindex > -1)             {                 themecolorview tc = (datagridview1.rows[e.rowindex].databounditem themecolorview);                  if (tc != null)                 {                     color c = color.fromname(tc.colortype.trim());                     brush b = new solidbrush(c);                      // know shoud changed here ;)                        e.graphics.fillrectangle(b, e.cellbounds);                     e.paintcontent(e.clipbounds);                       e.handled = true;                 }             }         } 

try comparing painted cell currentcell of grid:

if (e.rowindex > -1 && datagridview1.currentcell != null) {   if (e.columnindex == datagridview1.currentcell.columnindex &&       e.rowindex == datagridview1.currentcell.rowindex) {         e.graphics.fillrectangle(brushes.green, e.cellbounds);         e.paintcontent(e.cellbounds);         e.handled = true;   } } 

btw, make sure dispose of custom made brushes , pens.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -