728x90
홀수행과 짝수행의 배경색을 다르게 지정하는 방법이 아래 코드 한줄이면 된다.
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;
아래와 같은 코드도 한 행씩 건너뛰면서 배경색상을 다르게 준다.
for (int i = 1; i < dataGridView1.Rows.Count; i++)
{
if (i % 2 != 0)
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(240, 255, 240);
}
else
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
}
위 코드에서 Rows 대신에 Columns 를 하면 칼럼(column)의 배경색을 변경할 수 있다.
728x90
'C# > dataGridView' 카테고리의 다른 글
C# dataGridView 현재 Row의 셀값 읽어내기 (KeyUp), CurrentCell (0) | 2015.09.21 |
---|---|
C# dataGridView ContentClick 이벤트, MouseDown 이벤트 (0) | 2015.09.19 |
C# dataGridView 자동 번호 매기기( 원하는 칼럼에 ) (0) | 2015.09.04 |
C# dataGridView 선택된 셀 내용 Textbox 에 표시하기 (0) | 2015.09.04 |
C# dataGridView 기능 분석 (0) | 2015.09.03 |