Disable Cell Highlighting in a datagridview
The ForeColor/BackColor kludge wasn't working for me, because I had cells of different colors. So for anyone in the same spot, I found a solution more akin to actually disabling the ability.
Set the SelectionChanged
event to call a method that runs ClearSelection
private void datagridview_SelectionChanged(object sender, EventArgs e)
{
this.datagridview.ClearSelection();
}
The only way I've found to "disable" highlighting is to set the SelectionBackColor
and the SelectionForeColor
in the DefaultCellStyle
to the same as the BackColor
and ForeColor
, respectively. You could probably do this programmatically on the form's Load
event, but I've also done it in the designer.
Something like this:
Me.DataGridView1.DefaultCellStyle.SelectionBackColor = Me.DataGridView1.DefaultCellStyle.BackColor
Me.DataGridView1.DefaultCellStyle.SelectionForeColor = Me.DataGridView1.DefaultCellStyle.ForeColor