代碼如下:
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);
}
}
}
}