• 转:C#根据条件设置datagridview行的颜色


     1 private void LoadData()
     2         {
     3             DataTable tblDatas = new DataTable();
     4             tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
     5  
     6             tblDatas.Columns.Add("Name", Type.GetType("System.String"));
     7             tblDatas.Columns.Add("Version", Type.GetType("System.String"));
     8             tblDatas.Columns.Add("Age", Type.GetType("System.String"));
     9             tblDatas.Rows.Add(new object[] { 1, "a", "b", "12" });
    10             tblDatas.Rows.Add(new object[] { 2, "a", "b", "15" });
    11             tblDatas.Rows.Add(new object[] { 3, "a", "b", "30" });
    12             tblDatas.Rows.Add(new object[] { 4, "a", "b", "25" });
    13             tblDatas.Rows.Add(new object[] { 5, "a", "b", "30" });
    14  
    15             dataGridView1.DataSource = tblDatas;
    16         }
    17  
    18  private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    19         {
    20             if (e.RowIndex > -1)
    21             {
    22                 int intGrade = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells["dgvAge"].Value);
    23                 if (intGrade ==30)
    24                 {
    25                     dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
    26                 }
    27                 else if(intGrade==25)
    28                 {
    29                     dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Brown;
    30                 }
    31             }
    32         }
    33 --------------------- 
    34 作者:大米11 
    35 来源:CSDN 
    36 原文:https://blog.csdn.net/wk125570/article/details/78026923?utm_source=copy 
    37 版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    反射详解六
    反射详解五
    反射详解四
    反射详解三
    反射详解二
    mysql行转列
    mysql增删改查
    视图的使用
    js过滤
    错误集
  • 原文地址:https://www.cnblogs.com/chuhj/p/9776247.html
Copyright © 2020-2023  润新知