How to shade read only cells, while keeping the same background as non read only cells in datagridview

StackOverflow https://stackoverflow.com/questions/19742476

  •  03-07-2022
  •  | 
  •  

Question

I have a windows forms vb.net application that is using the datagridview control. I'm hoping to find a way to shade out read only cells and keep that same alternating background as my other cells. I ran across this image online and it does exactly what I wan't it to do. However I'm not sure how this can be done. Here is the picture below.

enter image description here

Was it helpful?

Solution

It can be done by setting some column properties. In the columns collection set the read only columns to ReadOnly, then open the DefaultCellStyle "style builder" and set the BackColor, SelectionBackColor and maybe SelectionForeColor to whatever you want.

At least in part, the colors you show look like they might be part of some Office based visual design style (the mix for RO + selected for instance looks custom (ie from RGB values) and non-Windows). To get the full effect you show, you may have to set the cell style for the other columns if for instance that is the not the default selected item color. The danger of full-on custom colors is that they can look terrible on systems using other color schemes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top