2011-10-24 123 views
4

現在datagridView標題背景顏色顯示爲灰色。我想改變顏色差異 。如何更改datagridView標題顏色

I更改了ColumnHeaderDefaultCellStyle中的背景顏色,但沒有任何更改。

如何做到這一點。

+1

dublicate? http://stackoverflow.com/questions/3921497/setting-gridview-header-color –

+0

@Soner,我使用基於Windows的應用程序 – Gopal

+1

@Gopal,那麼你應該簡單地給dataGridView而不是gridview。 –

回答

1

在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

+0

我正在使用基於Windows的應用程序..... – Gopal

+0

@Gopal現在提交 –

+0

顏色工作正常,但列標題分隔線不顯示... – Gopal

16

設置屬性EnableHeadersVisualStylesFalse,然後更改ColumnHeaderDefaultCellStyle背景顏色,你的願望顏色。您將能夠看到設計師本身的變化。