两种方法
第一种
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();
             
            }
        }

change color3的更多相关文章

  1. 代码的坏味道(10)——发散式变化(Divergent Change)

    坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...

  2. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  3. input事件与change事件

    输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.

  4. Change the Target Recovery Time of a Database (SQL Server) 间接-checkpoints flushcache flushcache-message

    Change the Target Recovery Time of a Database (SQL Server) 间接checkpoints   flushcache flushcache-mes ...

  5. Change Line Type in OpenCascade

    Change Line Type in OpenCascade eryar@163.com 关键字KeyWords:OpenCascade,Line Aspect, Line Type 在OpenCa ...

  6. 华硕笔记本U盘启动系统/WinPE报错。Windows failed to start. A Recent hardware or software change might be the cause.

    最近在整一台华硕笔记本,大概有5年寿命了吧,质量还行,由于系统出了问题,打算用自制U盘WinPE进去修复一下.按照个人经验,在主板设置里启用了USB启动选项,并且设置USB启动顺序为第一个,可是进系统 ...

  7. You cannot change a partition into an extended one or vice versa Delete it first

    在Linux扩展LVM时,使用fdisk创建分区时,在磁盘上新建扩展分区(逻辑分区),修改分区格式,指定分区类型为8e时,报错"You cannot change a partition i ...

  8. [WPF系列]基础 Listening to Dependency Property change notifications of a given Element

    I want to share this great post from Anoop that shows a easy way to add a notification system to dep ...

  9. 鼠标的change事件

    原本想着在<input>输入输入框中添加change事件,来实现对输入内容的限定. 当人们在使用时跟多的会直接去点击完成.所以完成按钮的点击事件会和change事件产生 冲突,所以我把验证 ...

随机推荐

  1. css 元素居中

    css 4种常见实现元素居中的办法: 1.通过 margin 属性调整 : { position: absolute; top: 50%; left: 50%; margin-left: 盒子的一半: ...

  2. bzoj 2733 永无乡 - 并查集 - 线段树

    永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以从一个岛 到达另一个岛. ...

  3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...

  4. 牛客网数据库SQL实战(21-25)

    21.查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_no以及其对应的薪水涨幅growth,并按照growth进行升序CREATE TABLE `employees` (`emp_no` i ...

  5. topcoder srm 685 div1

    problem1 link 依次枚举每个元素$x$,作为$S$中开始选择的第一个元素.对于当前$S$中任意两个元素$i,j$,若$T[i][j]$不在$S$中,则将其加入$S$,然后继续扩展:若所有的 ...

  6. 赞 ( 84 ) 微信好友 新浪微博 QQ空间 180 SSD故事会(14):怕TLC因为你不了解!【转】

    本文转载自:https://diy.pconline.com.cn/750/7501340.html [PConline 杂谈]从前,大家谈TLC色变:如今,TLC攻占SSD半壁江山.是的,这个世界就 ...

  7. Docker 入门指南——部署常用服务示例

    MongoDB FROM centos:centos7 MAINTAINER The CentOS Project <cloud-ops@centos.org> RUN yum -y up ...

  8. A^B mod C (快速幂+快速乘+取模)题解

    A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63). ...

  9. 关于msf反弹后门的免杀Tips

    msf是一个很强大的工具,我经常会在渗透用它来反弹shell,不过它生成的反弹后门会被不少杀软kill,这篇文章只是讲讲我在msf中一个简单的免杀小技巧 思路 我以前接触过一款python的远控,其实 ...

  10. (转)Introduction to Gradient Descent Algorithm (along with variants) in Machine Learning

    Introduction Optimization is always the ultimate goal whether you are dealing with a real life probl ...