WinForm DataGridView控件隔行变色
WinForm的DataGridView控件设置行的颜色
1 dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
隔行变色
1 /// <summary> 2 /// 隔行变色 3 /// </summary> 4 /// <param name="dgv">传入DataGridView控件名称</param> 5 public static void DgvRowColor(System.Windows.Forms.DataGridView dgv) 6 { 7 8 if (dgv.Rows.Count != 0) 9 { 10 for (int i = 0; i < dgv.Rows.Count; i++) 11 { 12 if ((i + 1) % 2 == 0) 13 { 14 dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White; 15 } 16 else 17 { 18 dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(224, 254, 254); 19 } 20 } 21 } 22 }