zoukankan      html  css  js  c++  java
  • 根据条件设置颜色

    public Form1()         {             InitializeComponent();             LoadData();
            }
            private void LoadData()         {             DataTable tblDatas = new DataTable();             tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
                tblDatas.Columns.Add("Name", Type.GetType("System.String"));             tblDatas.Columns.Add("Version", Type.GetType("System.String"));             tblDatas.Columns.Add("Age", Type.GetType("System.String"));             tblDatas.Rows.Add(new object[] { 1, "a", "b", "12" });             tblDatas.Rows.Add(new object[] { 2, "a", "b", "15" });             tblDatas.Rows.Add(new object[] { 3, "a", "b", "30" });             tblDatas.Rows.Add(new object[] { 4, "a", "b", "25" });             tblDatas.Rows.Add(new object[] { 5, "a", "b", "30" });
                dataGridView1.DataSource = tblDatas;         }
    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)         {             if (e.RowIndex > -1)             {                 int intGrade = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells["dgvAge"].Value);                 if (intGrade ==30)                 {                     dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;                 }                 else if(intGrade==25)                 {                     dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Brown;                 }             }         }

    效果图如下:

  • 相关阅读:
    如何克服晕车?
    简单C程序,迷宫
    非名校毕业年薪20W程序员 心得分享
    北京:一个大学生每年要花多少钱
    PowerPoint超链接字体颜色修改、怎么去掉超链接下划线
    河南旅游景点介绍
    程序员必看的十大电影
    AMD的cpu如何安装Mac OS
    C/C++面试之算法系列--去除数组中的重复数字
    Warshall算法
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/10585381.html
Copyright © 2011-2022 走看看