dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
隔行变色
/// <summary>
/// 隔行变色
/// </summary>
/// <param name="dgv">传入DataGridView控件名称</param>
public static void DgvRowColor(System.Windows.Forms.DataGridView dgv)
{
if (dgv.Rows.Count != 0)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
if ((i + 1) % 2 == 0)
{
dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
}
else
{
dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(224, 254, 254);
}
}
}
}