陈宝刚---享受生活,追逐梦想!
理想是心中的火焰,有追求的人才是幸福的人!
如果该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
申明:转帖,来自互联网。
posted on 2010-06-19 10:38  追梦人RUBY  阅读(206)  评论(0编辑  收藏  举报