Unable to change the column header text in DataGridView

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Hi,
Try following code:
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy
DataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
DataGridView1.ColumnHeadersDefaultCellStyle.Font = New
Font(songsDataGridView.Font, FontStyle.Bold)
 
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);
 
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.
 
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.
 
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.
 
Back
Top