Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i write below commands for change backcolor of HeaderCell of dataGridView :
C#
dataGridView2.Rows[0].HeaderCell.Style.BackColor = Color.Green;
dataGridView2.Rows[1].HeaderCell.Style.BackColor = Color.Green;

dataGridView2.ColumnHeadersDefaultCellStyle.ForeColor = Color.Orange;
dataGridView2.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
dataGridView2.RowHeadersDefaultCellStyle.BackColor = Color.Yellow;


but don't be work.
why?
thanks

What I have tried:

i don't know what should i do

help
Posted
Updated 6-Feb-19 21:48pm
v2

Try this:

C#
myDataGridView.EnableHeadersVisualStyles = false;
myDataGridView.Columns[col].HeaderCell.Style.BackColor = Color.Green;

VB.NET
myDataGridView.EnableHeadersVisualStyles = False
myDataGridView.Columns[col].HeaderCell.Style.BackColor = Color.Green



Points to OriginalGriff: How to change only DataGridView RowHeader's Grid Colour in C#.Net(Windows Application)[^]
 
Share this answer
 
this worked for me to change topleftcell:

 DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.Font = new Font("Verdana", 10, System.Drawing.FontStyle.Bold);
dataGridViewLabelsFromClient.TopLeftHeaderCell.Style = columnHeaderStyle;
 
Share this answer
 
Comments
CHill60 19-Jan-24 11:46am    
The OP wanted to change the backcolor not the font
DataGridViewCellStyle headerStyle = new DataGridViewCellStyle
{
BackColor = Color.LightBlue,
// Other style properties can be set here
};

foreach (DataGridViewColumn column in dataGridView1.Columns)
{
column.HeaderCell.Style.ApplyStyle(headerStyle);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900