zoukankan      html  css  js  c++  java
  • DataGridView隔行显示不同的颜色

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

    View Code

    如果没有绑定数据库,那么当dataGridView中的数据有所改变或显示的时候可以添加以下的代码:

    View Code
     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 }


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

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

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

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

  • 相关阅读:
    5、打开界面
    C++模版完全解析
    运维二三事儿
    tcpdump命令使用方法
    putty源码阅读----plink
    nginx--提供一键安装脚本
    vt100控制符
    zabbix---简介
    Dictionary
    装箱、拆箱
  • 原文地址:https://www.cnblogs.com/daytoday/p/2527812.html
Copyright © 2011-2022 走看看