zoukankan      html  css  js  c++  java
  • change color1

    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;                                         }                 }                  //第二种方法                 this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Red;//DataGridView行单元格默认颜色                 this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Violet;//奇数行单元格默认颜色

                }             catch (Exception ex)             {

                    MessageBox.Show(ex.Message);             }             finally             {                 mycon.Close();                         }         }

  • 相关阅读:
    java 多线程
    数据结构与算法-----快速排序
    JS 强制类型转化
    VS Code 编辑器
    MySQL8数据库安装配置和启动
    listview更改选中时item背景色(转)
    Android下用程序的方法为ListView设置分割线Divider样式
    listview android:cacheColorHint,android:listSelector属性作用
    Android手动显示和隐藏软键盘
    android调试debug快捷键
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/10585443.html
Copyright © 2011-2022 走看看