none
Change DataGridView column header text color

    Question

  • Hi there,

    I've been trying for the past hour to get the blasted column headers to have a different text color, with no success.  I have tried setting the 'DefaultCellStyle' on every single object in the DataGridView (just to make sure the cell style inheritance wasn't interfering) and - nothing.

    Now, it is very easy for me to simply paint the column headers myself.  But, I was hoping I didn't have to.  Am I missing something or does the DataGridView really not allow you to change the column header text color?

    Thanks!
    Sunday, January 28, 2007 2:31 AM

Answers

  • Set the datagridview's EnableHeadersVisualStyles to false to get the header cell to accept the color change



            CategoriesDataGridView.EnableHeadersVisualStyles = False
            CategoriesDataGridView.Columns(0).HeaderCell.Style.BackColor = Color.Blue


     

    Sunday, January 28, 2007 4:09 AM

All replies

  • Set the datagridview's EnableHeadersVisualStyles to false to get the header cell to accept the color change



            CategoriesDataGridView.EnableHeadersVisualStyles = False
            CategoriesDataGridView.Columns(0).HeaderCell.Style.BackColor = Color.Blue


     

    Sunday, January 28, 2007 4:09 AM
  • Perfect!

    This approach has the drawback that it disables the attractive gradient styling on the column headers, but that actually isn't a problem in my case - I'm overriding the OnCellPainting event anyway to paint a gradient background on the column headers.

    Thank you very much!
    Sunday, January 28, 2007 4:14 AM