Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatGridView Header Cell's Background Color

I want to Get the DataGridView Header Cell's Background color, I have done a trick but its giving me empty and RGB = 0,0,0

I have try this code:

 Color cl = dataGridView1.Columns["<Column>"].HeaderCell.Style.BackColor; //<AnyColumn>

I have to repaint Header Cell's Background of the same color as it has before repainting with size modifications .

Kindly Suggest a Solution, I have searched a lot but no useful help

like image 480
DareDevil Avatar asked Oct 27 '25 03:10

DareDevil


1 Answers

The DataGridView uses style inheritance, so unless an individual header cell differs from the default, its BackColor will be set to Color.Empty.

Try the ColumnHeadersDefaultCellStyle.BackColor property instead.

Note that when EnableHeadersVisualStyles is set to true (the default), the value will be ignored and the headers will be drawn using a visual style renderer instead.

like image 63
Bradley Smith Avatar answered Oct 29 '25 18:10

Bradley Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!