How to change the header backcolor in datagridview C#

Here I am trying to get the new design for my DataGridView header back color. So that, I have been tried a lot in Google and got the solution which is explained below.

Set the following properties for your DataGridView control by using the properties window.

EnableHeadersVisualStyles = False

RowHeadersBorderStyle = Raised

Then copy the following code in your Form_Load event.

DataGridViewCellStyle style = this.dataGridView1.ColumnHeadersDefaultCellStyle;
style.BackColor = Color.WhiteSmoke;
style.ForeColor = Color.Gray;
style.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

Now run your application, the header style would be changed and showing a new style that we wants.



Radhika said...

Thank you Vinoth. This code helped me at right time.

Giri said...

i work fine if we want plain color [flat style], but if we want 3D look then what to do, like displaying the headers in 3D format
[Vista style, XP]

how to apply theme for headers, is that possible to apply themes in window forms application?

how to apply gradiant colors to headers.


Vishwdeep said...

Thanks... S.Vinothkumar, This code is very userful for me because i am often use gridview control in my projects.

Shraddha said...

thank you very can we implement the same thing for column header...??