شطرنجی کردن Datagridview
برای رنگی کردن Datagridview به صورت شطرنجی ، می توانید از متد زیر استفاده کنید :
private void ColorfulDGV() { //Clear previous Style for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { for (int j = 0; j < this.dataGridView1.Columns.Count; j++) { this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.White; } } for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { if (i % 2 == 0) { for (int j = 0; j < this.dataGridView1.Columns.Count; j++) { if (j % 2 == 0) { this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.LightGray; } } } else { for (int j = 0; j < this.dataGridView1.Columns.Count; j++) { if (j % 2 != 0) { this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.LightGray; } } } } }
خروجی :