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         }

 

相关文章:

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