How to change the color of winform DataGridview header?

后端 未结 5 923
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 07:26

I have tried to do it without success.

Is it possible ?

相关标签:
5条回答
  • 2020-11-28 07:56
    dataGridView1.EnableHeadersVisualStyles = false;
    dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
    
    0 讨论(0)
  • 2020-11-28 07:56

    dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;

    0 讨论(0)
  • 2020-11-28 07:57

    If you want to change a color to single column try this:

     dataGridView1.EnableHeadersVisualStyles = false;
     dataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Magenta;
     dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Yellow;
    
    0 讨论(0)
  • 2020-11-28 08:04

    The way to do this is to set the EnableHeadersVisualStyles flag for the data grid view to False, and set the background colour via the ColumnHeadersDefaultCellStyle.BackColor property. For example, to set the background colour to blue, use the following (or set in the designer if you prefer):

    _dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
    _dataGridView.EnableHeadersVisualStyles = false;
    

    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. The MSDN documentation for this property is here.

    0 讨论(0)
  • 2020-11-28 08:07

    It can be done.

    From the designer: Select your DataGridView Open the Properties Navigate to ColumnHeaderDefaultCellStype Hit the button to edit the style.

    You can also do it programmatically:

    dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Purple;
    

    Hope that helps!

    0 讨论(0)
提交回复
热议问题