All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#,DataGridView隔行显示不同的颜色_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/27 6:49:09 Browse times: 313 Comment times: 0

C#,DataGridView隔行显示不同的颜色_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

C# DataGridView隔行显示不同的颜色_[Asp.Net教程]

  本文将向大家介绍在C#中如何通过编程实现让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;
  }
  }
  }

  如果没有绑定数据库,那么当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;
  }
  }


设计家园 整理




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.