i am not sure why you need to catch CellPainting event to change cell background color just do it like this
Daywisegrid.Rows[RowIndex].Cells[columnIndex].Style.BackColor = Color.Red;
But if you want to do it in painting try this
private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == 0 )
{
using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor))
{
using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// Clear cell
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
//Bottom line drawing
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1);
// here you force paint of content
e.PaintContent( e.ClipBounds );
e.Handled = true;
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…