您可以尝试在中设置背景色和前景色
CellFormatting
事件
void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
TrackedSet set = this._setLogBindingSource[e.RowIndex] as TrackedSet;
if (set.IsFlagged)
{
e.CellStyle.BackColor = Color.Blue;
e.CellStyle.ForeColor = Color.White;
}
else if (set.IsError)
{
e.CellStyle.BackColor = Color.Red;
e.CellStyle.ForeColor = Color.Blue;
}
}
要拥有自定义渐变背景,您可能仍然需要在
RowPrePaint
ForeColor
在
单元格格式
事件
DefaultCellStyle
在您将其绑定到DataGridView之后的行上,但我相信某些事件将触发DefaultCellStyle重置回
RowTemplate