DataGridView隔行显示不同的颜色

DataGridView隔行显示不同的颜色

Violinlins 2016-10-07 23:17:53  6738  收藏

分类专栏: C#

==================================

 

方法一、DataGridView隔行显示不同的颜色

AlternatingRowsDefaultCellStyle 属性
获取或设置应用于 DataGridView 的奇数行的默认单元格样式。

RowsDefaultCellStyle 属性
获取或设置应用于 DataGridView 的行单元格的默认样式。

只需要增加以下代码即可实现隔行变色:

dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige

 

、、============================================

 

方法二。

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

 1 private   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中的数据有所改变或显示的时候可以添加以下的代码:

1   if  ( 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  

申明:转帖,来自互联网。

  • 点赞1
  • 评论
  • 分享
  • 收藏
  • 举报
  • 关注
  • 一键三连

WinForm DataGridView控件隔行变色小例子

09-05

WinFormDataGridView控件设置行颜色

dataGridView隔行变色效果

自己想到或者看到整理后发布的地方

 989

AlternatingRowsDefaultCellStyle 属性获取或设置应用于 DataGridView 奇数行默认单元格样式。RowsDefaultCellStyle 属性 获取或设置应用于 DataGridView 行单元格默认样式。只需要增加以下代码即可实现隔行变色dataGridView1.RowsDefaultCellStyle.BackColor = Colo

表情包

 

相关推荐

C# DataGridView隔行显示不同颜色_sunchanglong专栏

5-29

本文将向大家介绍在C#中如何通过编程实现让DataGridView控件隔行显示不同颜色…… 如果该dataGridView是跟数据库绑定,则可以触发DataBindingComplete事件: private void dataGridView1_DataBindingComplete(object sender, DataGridViewBinding...

C# DataGridView隔行显示不同颜色 _学无止境专栏

5-22

如果没有绑定数据库,那么当dataGridView数据有所改变或显示时候可以添加以下代码: if(this.dataGridView1.Rows.Count!=0) { for(inti=0; i<this.dataGridView1.Rows.Count; )

excel中怎样设置隔行隔列显示不同颜色

mystonelxj的博客

 1万+

不同office版本略有差异,这里以Excel2007为例,说明下怎么设置 1,首先选择所有数据,本例以中国50强企业为例 2,选择开始菜单下‘条件格式’按钮,点击“新建规则”菜单 3,在“新建格式规则”对话框中点击“使用公式确定要设置格式单元格”,在“为符合公式值设置格式”区域输入“=mod(row(),2)” 4,点击“格式”按钮,弹出“设置单元格格式”对话框 ...

DataGridView合并单元格(一列或一行)

cdzyg的博客

 1455

#region"合并单元格测试(一列或一行)" // int?是搜索一种类型(可空类型),普通int不能为null,而用int?,其值可以为null //private int? nextrow = null; //private int? nextcol = null; //在CellPainting方法后调用 privatevoiddataGridView1_CellF...

C# DataGridView隔行显示不同颜色_changjiangzhibin...

5-10

本文将向大家介绍在C#中如何通过编程实现让DataGridView控件隔行显示不同颜色…… 如果该dataGridView是跟数据库绑定,则可以触发DataBindingComplete事件: private void dataGridView1_DataBindingComplete(object sender, DataGridViewBinding...

C# DataGridView隔行显示不同颜色_adaiye专栏

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值