Akshay J
Akshay J

Reputation: 5458

DataGridViewColumnHeader Make Bold

I have one DataGridView and want to make the Header text Bold. I have tried changing the ColumnHeaderDefaultCellStyle to
DataGridViewCellStyle { BackColor=Color [Control], SelectionBackColor=Color [Highlight], SelectionForeColor=Color [HighlightText], Font=[Font: Name=Tahoma, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont=False], WrapMode=True, Alignment=MiddleCenter }

In the designer I can see the Headers as Bold but at runtime it shows as normal. Please not that apart from ColumnHeaderDefaultCellStyle I am also changing DefaultCellStyle of DataGridView as well as of Individual Columns.

How to make the headers bold ?

Upvotes: 17

Views: 82155

Answers (3)

Shree D
Shree D

Reputation: 51

This is with respect to the @Shaahin comment.

Here put dataGridView1.ColumnHeadersDefaultCellStyle.Font instead of DataGridView.DefaultFont
Here we are re-assigning the font to the datagridview so we have to apply the font same datagridview's font not DataGridView.DefaultFont.
In working conditions DataGridView.DefaultFont and dataGridView1.ColumnHeadersDefaultCellStyle.Font may have different values

dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font(dataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);

The above code is converted from a VB.Net to C#.Net by some tool. Please don't go for syntax rather concept.

Upvotes: 1

Shaahin
Shaahin

Reputation: 1225

Try this:

dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Bold);

Upvotes: 14

Alex R.
Alex R.

Reputation: 4754

Suppose you want to change the style of column 0 of DataGridView myDataGrid:

myDataGrid.Columns[0].HeaderCell.Style.Font = new Font("Tahoma", 9.75F, FontStyle.Bold);

If you want to change the default for headers:

myDataGrid.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9.75F, FontStyle.Bold);

EDIT:

In the designer you can click on the properties box of the control, click on the small box beside ColumnHeadersDefaultCellStyle property, expand Font and set Bold=True:

Upvotes: 52

Related Questions