How do I change the datagridview selected row background color in C# windows applications?
+2
A:
On the DataGridView there is a DefaultCellStyle
, inside this there is SelectionBackColor
and SelectionForeColor
properties.
The DataGridView uses a style inheritance idea, in case you find that the style you pick is not being applied:
Adam
2010-07-05 09:33:22
A:
Taking advantage of DataGridViewCell
's events CellEnter
and CellLeave
you might try something like this:
private void foobarDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCellStyle fooCellStyle = new DataGridViewCellStyle();
fooCellStyle.BackColor = System.Drawing.Color.LightYellow;
this.VariableFinderDataGridView.CurrentCell.Style.ApplyStyle(fooCellStyle);
}
private void foobarFinderDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCellStyle barCellStyle = new DataGridViewCellStyle();
barCellStyle.BackColor = System.Drawing.Color.White;
this.VariableFinderDataGridView.CurrentCell.Style.ApplyStyle(barCellStyle);
}
Nano Taboada
2010-07-13 17:11:32