`
dzgwt2004
  • 浏览: 165089 次
  • 来自: 浙江杭州
社区版块
存档分类
最新评论

DataGridView隔行显示不同的颜色

    博客分类:
  • C#
 
阅读更多
如果该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;
                }
            }
}

如果没有绑定数据库,那么当dataGridView中的数据有所改变或显示的时候可以添加以下的代码:
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;
                }
            }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics