'dataGridView 배경색'에 해당되는 글 1건

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)의 배경색을 변경할 수 있다.

블로그 이미지

Link2Me

,