Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of winform DataGridview header?

I have tried to do it without success.

Is it possible ?

like image 994
programmernovice Avatar asked Aug 08 '09 02:08

programmernovice


2 Answers

The way to do this is to set the EnableHeadersVisualStyles flag for the data grid view to False, and set the background colour via the ColumnHeadersDefaultCellStyle.BackColor property. For example, to set the background colour to blue, use the following (or set in the designer if you prefer):

_dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue; _dataGridView.EnableHeadersVisualStyles = false; 

If you do not set the EnableHeadersVisualStyles flag to False, then the changes you make to the style of the header will not take effect, as the grid will use the style from the current users default theme. The MSDN documentation for this property is here.

like image 115
Rhys Jones Avatar answered Oct 27 '22 05:10

Rhys Jones


dataGridView1.EnableHeadersVisualStyles = false; dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue; 
like image 22
mahvash Avatar answered Oct 27 '22 06:10

mahvash