I have a DataGridView
bound to a list of objects, and I'm setting a dynamic cell background colour using the CellFormatting
event, as in this answer. This works well for every column except the DataGridViewCheckboxColumn
. When I click inside this cell (but outside the checkbox) the cell background changes to the default white.
Visually it looks like cell selection is occurring, despite my best efforts to stop it. My cell formatting code sets the SelectionBackColor
as well as the BackColor
. I've disabled cell selection using the CellStateChanged
event, and none of the other columns are selectable:
private void PlayerGrid_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e) { if (e.StateChanged == DataGridViewElementStates.Selected) e.Cell.Selected = false; }
Is there an extra workaround to override the cell behaviour for checkboxes?