原理就是先判断所在的行是偶数行还是奇数行,然后设置当前行的当前样式为需要的就可以了。

SqlConnection conn = new SqlConnection(@"数据库连接字符串");
SqlDataAdapter sda
= new SqlDataAdapter("select * from CarColor", conn);
DataSet ds
= new DataSet();
sda.Fill(ds);
dataGridView1.DataSource
= ds.Tables[0];
dataGridView1.SelectionMode
= DataGridViewSelectionMode.FullRowSelect;
foreach (DataGridViewRow dgvr in dataGridView1.Rows)
{
if (dgvr.Index % 2 == 0)
{
dataGridView1.Rows[dgvr.Index].DefaultCellStyle.BackColor
= Color.WhiteSmoke;

}
else
{
dataGridView1.Rows[dgvr.Index].DefaultCellStyle.BackColor
= Color.LightCyan;
}
}

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2022-01-17
  • 2021-12-11
  • 2021-12-08
  • 2022-12-23
  • 2022-01-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-10-21
  • 2021-12-19
相关资源
相似解决方案