I have a couple of issues doing datagridviewcheckboxcell painting of background color and was looking for advice.
My datagridview contains a few checkboxcolumns and a few textcolumns. In my datagridview's cell formatting event I look at the formatted value of the cell if the column is the checkbox type. If the value is true I set the cell.style.backcolor to green, otherwise it gets red backcolor.
code:
![Name: Capture2.PNG
Views: 39
Size: 14.9 KB]()
This code works for all rows but the default selected row of zero.
See:
![Name: Capture.PNG
Views: 32
Size: 16.8 KB]()
Row 0 is inheriting the default row cellstyle which is white background with black foreground. Selected color foreground is black and background is transparent.
When I select another row on the grid the selection results in the red/green color remaining. The alternating and default row styles have selected background colors of transparent so this is what I expected. I just don't understand why the first row is ignoring the cell formating.
That's my first problem.
My second problem is when I check/uncheck one of these cells the ui updates with the checkstate being drawn but it doesn't update the color from red to green or from green to red. Even if I pass the actual cell into the invalidatecell routine on the datagridview the result is no color change. Not sure what i'm doing wrong here either.
![Name: capture3.png
Views: 37
Size: 17.1 KB]()
I have a big feeling that my lack of understanding of the order of datagridview events is what is throwing me off here.
If anybody has time to review and help me figure this out I would appreciate it. Happy Holidays everyone!
My datagridview contains a few checkboxcolumns and a few textcolumns. In my datagridview's cell formatting event I look at the formatted value of the cell if the column is the checkbox type. If the value is true I set the cell.style.backcolor to green, otherwise it gets red backcolor.
code:
This code works for all rows but the default selected row of zero.
See:
Row 0 is inheriting the default row cellstyle which is white background with black foreground. Selected color foreground is black and background is transparent.
When I select another row on the grid the selection results in the red/green color remaining. The alternating and default row styles have selected background colors of transparent so this is what I expected. I just don't understand why the first row is ignoring the cell formating.
That's my first problem.
My second problem is when I check/uncheck one of these cells the ui updates with the checkstate being drawn but it doesn't update the color from red to green or from green to red. Even if I pass the actual cell into the invalidatecell routine on the datagridview the result is no color change. Not sure what i'm doing wrong here either.
I have a big feeling that my lack of understanding of the order of datagridview events is what is throwing me off here.
If anybody has time to review and help me figure this out I would appreciate it. Happy Holidays everyone!