Unable to change the column header text in DataGridView

G

Guest

I am trying to change the column header text to red and I have this code:

dCol.HeaderCell.Style.ForeColor = Color.Red;

This change does indeed stick and I can see it in the debugger. However,
the column name text is still showing up as black. I have seen this same
problem asked around but with no answer. Does anybody know what is going on?

Thanks.
 
G

Guest

Hi,
Try following code:
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy
DataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
DataGridView1.ColumnHeadersDefaultCellStyle.Font = New
Font(songsDataGridView.Font, FontStyle.Bold)
 
G

Guest

Hi,
In order to set forecolor/backcolor of particular column you can something
like this:
DataGridView1..Columns[4].DefaultCellStyle.BackColor = Color.Navy
DataGridView1..Columns[4].DefaultCellStyle.ForeColor = Color.White
dataGridView1.Columns[4].DefaultCellStyle.Font = new
Font(DataGridView.DefaultFont, FontStyle.Italic);
 
G

Guest

Wouldn't that change the colors of all the cells in that column?
I just want the header cell text color to change.

Manish Bafna said:
Hi,
In order to set forecolor/backcolor of particular column you can something
like this:
DataGridView1..Columns[4].DefaultCellStyle.BackColor = Color.Navy
DataGridView1..Columns[4].DefaultCellStyle.ForeColor = Color.White
dataGridView1.Columns[4].DefaultCellStyle.Font = new
Font(DataGridView.DefaultFont, FontStyle.Italic);
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Oldman said:
I am trying to change the column header text to red and I have this code:

dCol.HeaderCell.Style.ForeColor = Color.Red;

This change does indeed stick and I can see it in the debugger. However,
the column name text is still showing up as black. I have seen this same
problem asked around but with no answer. Does anybody know what is going on?

Thanks.
 
G

Guest

Hi,
Try this code:
dataGridView.Rows(0).Cells(2).DefaultCellStyle.BackColor = Color.Navy
//for setting backcolor of second column
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Oldman said:
Wouldn't that change the colors of all the cells in that column?
I just want the header cell text color to change.

Manish Bafna said:
Hi,
In order to set forecolor/backcolor of particular column you can something
like this:
DataGridView1..Columns[4].DefaultCellStyle.BackColor = Color.Navy
DataGridView1..Columns[4].DefaultCellStyle.ForeColor = Color.White
dataGridView1.Columns[4].DefaultCellStyle.Font = new
Font(DataGridView.DefaultFont, FontStyle.Italic);
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Oldman said:
I am trying to change the column header text to red and I have this code:

dCol.HeaderCell.Style.ForeColor = Color.Red;

This change does indeed stick and I can see it in the debugger. However,
the column name text is still showing up as black. I have seen this same
problem asked around but with no answer. Does anybody know what is going on?

Thanks.
 
G

Guest

I found the problem. I needed to set EnableHeadersVisualStyles = false.

Manish Bafna said:
Hi,
Try this code:
dataGridView.Rows(0).Cells(2).DefaultCellStyle.BackColor = Color.Navy
//for setting backcolor of second column
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Oldman said:
Wouldn't that change the colors of all the cells in that column?
I just want the header cell text color to change.

Manish Bafna said:
Hi,
In order to set forecolor/backcolor of particular column you can something
like this:
DataGridView1..Columns[4].DefaultCellStyle.BackColor = Color.Navy
DataGridView1..Columns[4].DefaultCellStyle.ForeColor = Color.White
dataGridView1.Columns[4].DefaultCellStyle.Font = new
Font(DataGridView.DefaultFont, FontStyle.Italic);
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



:

I am trying to change the column header text to red and I have this code:

dCol.HeaderCell.Style.ForeColor = Color.Red;

This change does indeed stick and I can see it in the debugger. However,
the column name text is still showing up as black. I have seen this same
problem asked around but with no answer. Does anybody know what is going on?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top