Say I have a datagridview filled with rows.
Now to make certain data more distinct I’d like to color the background of certain cells.
There’s some caveats though, the amount of columns I want coloring in can vary.
To make things more clear I’ll sketch up a fake datagrid:
Name Thing2 col1 col2 col3
tes test 1 1 2
t2t ers 3 3 3
der zoef 2 3 1
Now, the col1-col3 cells need to be colored, depending on their value. The cells in the first column will always be green (by convention) cells deviating from it will be colored red.
So, the first row will have col1 and col2 colored green and col3 red et cetera.
Any ideas to how i’d best approach this problem?
I suggest using CellFormating event.
First get object associated with current row using
e.RowIndexand then color current cell according to current column (e.ColumnIndex) and your object’s properties.