zoukankan      html  css  js  c++  java
  • WinForm DataGridView控件隔行变色

    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         }
  • 相关阅读:
    基于typora编写Markdown文档
    VMware Workstation常见的故障处理
    VMware Workstation产品常用的快捷键
    2
    1
    9
    8
    7
    6
    5
  • 原文地址:https://www.cnblogs.com/rwen/p/2966731.html
Copyright © 2011-2022 走看看