WinForm DataGridView控件隔行变色

不问归期 提交于 2020-03-17 05:09:53

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         }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!