zoukankan      html  css  js  c++  java
  • DataGridView隔行显示不同的颜色

     

     
    如果该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
    复制代码
    申明:转帖,来自互联网。
  • 相关阅读:
    ApiKernel
    ApiUser
    BringWindowToTop完美激活窗口与置顶
    poj2486 Apple Tree【区间dp】
    HYSBZ1588 营业额统计【Splay】
    hdu5115 Dire Wolf【区间dp】
    poj1144 Network【tarjan求割点】
    poj1236 Network of Schools【强连通分量(tarjan)缩点】
    poj2342 Anniversary party【树形dp】
    poj2449 Remmarguts' Date【A*算法】
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/4047694.html
Copyright © 2011-2022 走看看