zoukankan      html  css  js  c++  java
  • 隔行颜色

    方法一、DataGridView隔行显示不同的颜色

    AlternatingRowsDefaultCellStyle 属性 获取或设置应用于 DataGridView 的奇数行的默认单元格样式。
    RowsDefaultCellStyle 属性 获取或设置应用于 DataGridView 的行单元格的默认样式。
    只需要增加以下代码即可实现隔行变色:
    dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque; dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige

    、、============================================

    方法二。

    如果该dataGridView是跟数据库绑定的,则可以触发DataBindingComplete事件:

     1private   void   dataGridView1_DataBindingComplete(object   sender,   DataGridViewBindingCompleteEventArgs   e)      2{     3            if (this.dataGridView1.Rows.Count != 0)     4            {     5                for (int i = 0; i < this.dataGridView1.Rows.Count; )     6                {     7                    this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;     8                    i += 2;     9                }    10            }    11}  
     
    如果没有绑定数据库,那么当dataGridView中的数据有所改变或显示的时候可以添加以下的代码:
    1if (this.dataGridView1.Rows.Count != 0)    2            {    3                for (int i = 0; i < this.dataGridView1.Rows.Count; )    4                {    5                    this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;    6                    i += 2;    7                }    8            }   9

    申明:转帖,来自互联网。

  • 相关阅读:
    【模版 Luogu P3808/P3796/P5357】AC自动机(简论)
    2019暑假 诸暨海亮集训游记
    【数据结构模版】可持久化线段树 && 主席树
    2019浙江集训——待整理的知识点、博客和题解
    浅谈树链剖分 F&Q
    Luogu P1967 NOIP2013 货车运输
    最小树形图(朱刘算法)--学习笔记
    Luogu P43916 图的遍历
    pytest扫盲12--assert断言
    pytest扫盲11--xfail参数详解
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/10585373.html
Copyright © 2011-2022 走看看