InitializeComponent();
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9.75F, FontStyle.Bold); // HEADER FONT BOLD
this..CellBorderStyle = DataGridViewCellBorderStyle.None;
this.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(250, 243, 198); // change back color of header cells
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex > -1)
{
// REMOVE COMPLETE CELL DIVISION AND CHANGE BACK COLOR
e.Handled = true;
using (Brush b = new SolidBrush(this.ColumnHeadersDefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(b, e.CellBounds);
}
e.PaintContent(e.ClipBounds);
e.PaintBackground(e.CellBounds, true);
Rectangle r = e.CellBounds;
r.X -= 2;
// Check if it's the first column
if (e.ColumnIndex == 0)
{ // Adjust the padding for the first column
r.X += 4;
// Align the text to the right for the first column
TextRenderer.DrawText(e.Graphics, this.Columns[e.ColumnIndex].HeaderText, e.CellStyle.Font, r, e.CellStyle.ForeColor, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
}
else
{
// Align the text to the left for other columns
TextRenderer.DrawText(e.Graphics, this.Columns[e.ColumnIndex].HeaderText, e.CellStyle.Font, r, e.CellStyle.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
}
// 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);
}
}
}
the above code i am using inside datagridview , asked by some other user here in microsoft a nd a , and modified by me according to my requirement . but the above logic is not working properly . i can see that there is some border visible between the columns division .
Thanks in advance