2011-10-24 5 views
4

이제 DataGridView 헤더 배경색이 회색으로 표시됩니다. differenct 색상으로 변경하고 싶습니다.DataGridView 헤더 색상을 변경하는 방법

배경색을 ColumnHeaderDefaultCellStyle으로 변경했지만 아무 것도 변경되지 않았습니다.

수행 방법.

+1

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

+0

@Soner, Windows 기반 응용 프로그램을 사용 중입니다. – Gopal

+1

@ Gopal, 그러면 gridview가 아닌 ​​dataGridView를 제공해야합니다. –

답변

1
당신이 DataGridViewCellStyle를 사용하여 헤더의 색상을 변경할 수있는 DataGridView에서

, 다음 코드

 ' 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를 사용

를 헤더 색상 것이다 변경하지만 헤더의 열위한 구분자 섹션이 나타나지 않습니다. 그래서를 heres의 OnPaint 이벤트 핸들러의 오버라이드 이벤트는 다음 원하는 색상으로 ColumnHeaderDefaultCellStyle 배경 색상을 변경, 재산 EnableHeadersVisualStylesFalse로 설정 this

+0

Windows 기반 응용 프로그램을 사용 중입니다 ..... – Gopal

+0

@Gopal 지금 참조하십시오. –

+0

색상은 잘 작동하지만 열 머리글 구분선이 표시되지 않습니다 ... – Gopal

16

를 보라. 디자이너 자체의 변경 사항을 볼 수 있습니다.

관련 문제