現在datagridView標題背景顏色顯示爲灰色。我想改變顏色差異 。如何更改datagridView標題顏色
I更改了ColumnHeaderDefaultCellStyle
中的背景顏色,但沒有任何更改。
如何做到這一點。
現在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://stackoverflow.com/questions/3921497/setting-gridview-header-color –
@Soner,我使用基於Windows的應用程序 – Gopal
@Gopal,那麼你應該簡單地給dataGridView而不是gridview。 –