c# - DataGridView getting the background colour -


i can't seem return background color of current cell in datagridview. example lets background style.backgroundcolor color of cells in grid color.pink

code:

private void grid_cellenter(object sender, datagridviewcelleventargs e)     {         var cell = grid.currentcell;         var colour = cell.style.backcolor;     } 

this var colour black. wrong code.

it depends on method used set background color. if have used like:

grid.rows[r].defaultcellstyle.backcolor = color.pink; 

you can color value defaultcellstyle, , cell.style.backcolor empty , returns rgb(0,0,0) or black. need change code to:

var colour = grid.rows[cell.rowindex].defaultcellstyle.backcolor; 

or

var colour = grid.currentrow.defaultcellstyle.backcolor; 

but if setting colors used like:

grid.rows[r].cells[c].style.backcolor = color.pink; 

the cell.style.backcolor has color.pink value , code works.

when set colors @ design time changing properties of datagridview, need use first method color value.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -