首页 > 编程 > C# > 正文

WinForm DataGridView控件隔行变色的小例子

2020-01-24 03:32:18
字体:
来源:转载
供稿:网友

复制代码 代码如下:

 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);
                     }                 
                 }
             }
         }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表