如何更改datagridView标题颜色
问题描述:
现在datagridView标题背景颜色显示为灰色。我想改变颜色差异 。如何更改datagridView标题颜色
I更改了ColumnHeaderDefaultCellStyle
中的背景颜色,但没有任何更改。
如何做到这一点。
答
在DataGridView中,你可以通过使用DataGridViewCellStyle改变标题颜色,请看下面的代码
' Set the selection background color for all the cells.
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black
' Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
' value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty
' Set the background color for all rows and for alternating rows.
' The value for alternating rows overrides the value for all rows.
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray
' Set the row and column header styles.
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black
dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black
编辑:
使用的DataGridViewCellStyle,你的头颜色会变化,但在标题为列分隔符部分不会出现。因此,继承人的OnPaint事件处理程序的overrided事件看看this
答
设置属性EnableHeadersVisualStyles
到False
,然后更改ColumnHeaderDefaultCellStyle
背景颜色,你的愿望颜色。您将能够看到设计师本身的变化。
dublicate? http://*.com/questions/3921497/setting-gridview-header-color –
@Soner,我使用基于Windows的应用程序 – Gopal
@Gopal,那么你应该简单地给dataGridView而不是gridview。 –