DataGridView隔行显示不同的颜色

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

private   void   dataGridView1_DataBindingComplete(object   sender,   DataGridViewBindingCompleteEventArgs   e)    

 {   
           if (this.dataGridView1.Rows.Count != 0)   
           {   
               for (int i = 0; i < this.dataGridView1.Rows.Count; )   
               {   
                   this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;   
                   i += 2;   
               }   
           }   

}
      if (this.dataGridView1.Rows.Count != 0)   
           {   
               for (int i = 0; i < this.dataGridView1.Rows.Count; )   
               {   
                   this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;   
                   i += 2;   
               }   
           }  

 

posted @ 2014-05-06 10:00  吻上明天  阅读(369)  评论(0编辑  收藏  举报