I have a DataGridView with a checkbox column and some text columns, and I want any row that has its checkbox column checked to have a different BackColor. I use the CellValueChanged event to highlight the cells as desired and this is working FAIRLY well, except that the formatting gets out of whack under certain circumstances.
If I add 10 rows to the grid and I sort by the checkbox column in descending order (checked rows at the top) and then I check the checkbox in the first 5 rows, they all get highlighted just fine. However, if I then un-check one of the middle ones (let's say the second row) the CellValueChanged event fires as expected, which un-highlights that second row. When I then leave the row and select another one, the column sorting kicks in and pushes row #2 down so that it's now row #5, which is ALSO correct.
The problem is that the sorting takes places AFTER the formatting, so the old row style is now applied to whatever row is now in that spot. It might be easier to show in a picture. The top screenshot shows the correct setup, then I uncheck the row with the # ending in "144" and switch to the last row. The result is that 144 moves from row #2 to row #5, and now row #2 has the "unhighlighted" style, even though the data row has the box checked:

Some supplemental info: I allow the user to check the box by clicking on it, or they can also multi-select rows and hit the spacebar to toggle the checkboxes. When I toggle the checkbox, I'm setting the Value property of the DataGridViewCell object to true or false.
Anyway, I'm trying to think of a good way to address this UI issue without looping through every row in the grid every time, which seems really inefficent. Any thoughts?