Как я изменяюсь, datagridview выбрал цвет фона строки в приложениях Windows C#?
В DataGridView есть свойства DefaultCellStyle
, внутри него - свойства SelectionBackColor
и SelectionForeColor
.
DataGridView использует идею наследования стилей на случай, если вы обнаружите, что выбранный вами стиль не применяется:
Использование преимуществ событий DataGridViewCell
CellEnter
и CellLeave
вы можете попробовать что-то вроде этого:
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);
}