Hi @Sushil Agarwal ,
You need to set the EnableHeadersVisualStyles
flag of the datagridview to False
, and set the background color through the ColumnHeaders DefaultCellStyle. BackColor
property.
If you do not set the EnableHeadersVisualStyles
flag to False
, then the changes you make to the style of the header will not take effect, as the grid will use the style from the current users default theme.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.enableheadersvisualstyles?redirectedfrom=MSDN&view=windowsdesktop-6.0#System_Windows_Forms_DataGridView_EnableHeadersVisualStyles
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
dataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Magenta;
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Yellow;
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.