Respecting alternating row coloring when coloring cells in a DataGridView

996 Views Asked by At

Similar to this question I'm trying to color individual cells in a DataGridView in c#. I'd like to support coloration for alternating rows though. My view does toggle row visibility and allows sorting, so I can't just use Index mod 2 to figure out which color to use. Is there any way to do this?

Also, this is for a VSTO plug-in to MS Project, so I don't believe the (very nice) css solutions are applicable.

Thanks!

1

There are 1 best solutions below

1
On

css is the best way to do it.

set CssClass="gridview"

then in css

  .gridview td :even
  {
  background-color: #CCC;
   }

    .gridview td :odd
   {
     background-color: #fff;
     }