DatGridView Header Cell's Background Color

c#, colors, datagridview, paint

Solution

After some efforts, I finally write down code with some suggestions Its a Generic Code that can be call at any Grid's Paint Method of C# WinForm, pass it the Grid,The Columns's names, and the paint Graphics object

I have added a fill rectangle of size 4, that starts from the previous column's Right-2 to Next Column's Left+2 , So it hides the Vertical Bar

Public Sub VerticalBarHide(ByVal grd As KryptonExtendedGrid, ByVal colname As String(), ByVal e As System.Drawing.Graphics)
    Dim rectHeader As Rectangle
    grd.EnableHeadersVisualStyles = False
    Dim bgColor As Color
    bgColor = grd.ColumnHeadersDefaultCellStyle.BackColor
    For Each name As String In colname
        rectHeader = grd.GetCellDisplayRectangle(grd.Columns(name).Index, -1, True)
        rectHeader.X = rectHeader.X + rectHeader.Width - 2
        rectHeader.Y += 1
        rectHeader.Width = 2 * 2
        rectHeader.Height -= 2
        e.FillRectangle(New SolidBrush(bgColor), rectHeader)
    Next

End Sub

Problem

I want to Get the DataGridView Header Cell's Background color, I have done a trick but its giving me empty and RGB = 0,0,0 I have try this code: ``` Color cl = dataGridView1.Columns["<Column>"].HeaderCell.Style.BackColor; //<AnyColumn> ``` I have to repaint Header Cell's Background of the same color as it has before repainting with size modifications . Kindly Suggest a Solution, I have searched a lot but no useful help

Original source