zoukankan      html  css  js  c++  java
  • change color3

    两种方法
    第一种
    DataGridview1.Rows[i].DefultCellStyle.backcolor
    第二种
    AlternatingRowsDefutCellstyle 属性
    获取或设置应用于DataGridview的奇数行的默认单元格样式。
     
    RowsDefultCellStyle 属性
      获取或设置应用于DataGridview的行单元格的默认样式。
     
            private void Form1_Load(object sender, EventArgs e)
            {
                string str = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";
                SqlConnection mycon = new SqlConnection(str);
                try
                {
                    mycon.Open();
                    DataSet mydt = new System.Data.DataSet();//建立填充数据库
                    SqlDataAdapter mydpt = new SqlDataAdapter("select * from book",mycon);//建立适配器
                    mydpt.Fill(mydt);
                    dataGridView1.DataSource = mydt.Tables[0];//数据源绑定的是表不是数据库,所以要指定表,索引值从0开始  说明book这个表是数据库中第一个表
     
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (i % 2 == 0)
                        {
                            this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Beige;
                        }
                        else
                        {
                            this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                         
                        }
                    }
     
                }
                catch (Exception ex)
                {
     
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    mycon.Close();
                 
                }
            }
  • 相关阅读:
    关于 NSTimer 和 NSRunLoop 的一些理解
    通过 CocoaPods 集成 WeexSDK 到iOS项目中
    iOS 从相册取出的图片默认 取中间部分 裁剪成方形的
    Trilynn分享了炼数成金邀请码
    highcharts分段显示不同颜色
    H5手机开发锁定表头和首列(惯性滚动)解决方案
    为移动端开发提供纯前端的路由方案
    ionic系列
    2014总结
    margin 相关 bug 系列
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/10585446.html
Copyright © 2011-2022 走看看