Hi @vijay kumar , Welcome to Microsoft Q&A,
You only need to delete the uneditabledatagridview_CellPainting event, and put the corresponding online and offline codes in the OncelPainting event.
The original code doesn't work because you draw the rectangle again.
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
if(e.RowIndex == -1 && e.ColumnIndex > -1)
{
e.Handled = true;
using(Brush b = new SolidBrush(this.DefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(b, e.CellBounds);
}
e.PaintContent(e.ClipBounds);
// Draw top double border
int topBorderThickness = 3; // Set the thickness of the top border
int bottomBorderThickness = 1; // Set the thickness of the bottom border
int x = e.CellBounds.Left;
int yTop = e.CellBounds.Top;
int yBottom = e.CellBounds.Bottom - bottomBorderThickness;
int width = e.CellBounds.Width;
using(Pen topBorderPen = new Pen(Color.Black, topBorderThickness))
using(Pen bottomBorderPen = new Pen(Color.Black, bottomBorderThickness))
{
// Draw top border
e.Graphics.DrawLine(topBorderPen, x, yTop, x + width, yTop);
// Draw bottom border
e.Graphics.DrawLine(bottomBorderPen, x, yBottom, x + width, yBottom);
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.