开发者

How can i change the background color of datagridview headercell in code using C#?

开发者 https://www.devze.com 2022-12-09 01:19 出处:网络
I want to change the backcolor of a headercell in datagridview row .So how can I do that in code C#? Also, how do I change font properties of the text named as v开发者_如何学Pythonalue of the headerc

I want to change the backcolor of a headercell in datagridview row .So how can I do that in code C#?

Also, how do I change font properties of the text named as v开发者_如何学Pythonalue of the headercell like headercell.value?


You can do this in the properties window. Set EnableHeadersVisualStyles to false then make the changes to the font, cell color, alignment, etc in ColumnHeadersDefaultCellStyle.


To change the font properties of a specified header cell you can try:

dataGridView1.Columns[index].HeaderCell.Style.Font = new Font("Arial", 24, , FontStyle.Bold);


you can try this

dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Columns[index].HeaderCell.Style.Font = new Font("Arial", 24, , FontStyle.Bold);


I've figured out how to change the backcolor using:

dataGridView1.Rows[index].HeaderCell.Style.BackColor = System.Drawing.Color.Red;

I still don't know the answer to my second question.

0

精彩评论

暂无评论...
验证码 换一张
取 消