zoukankan      html  css  js  c++  java
  • DataGridView 单元格背景颜色

    private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
            {
                if (e.RowIndex >= dataGridView1.Rows.Count - 1)
                    return;
                DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
                try
                {
                    string[] Flag = dgr.Cells["Flag"].Value.ToString().Split('-');
                    DataGridViewCellStyle cstyle = new DataGridViewCellStyle();
                    cstyle.BackColor = Color.GreenYellow;

                    for (int i = 0; i < Flag.Length; i++)
                    {
                        if (Flag[i] == "1")
                        {

                            //dgr.DefaultCellStyle.ForeColor = Color.Blue;

                            dgr.Cells[0].Style = cstyle;
                        }
                        if (Flag[i] == "2")
                        {

                            //dgr.DefaultCellStyle.ForeColor = Color.Blue;
                            dgr.Cells[1].Style = cstyle;
                        }
                        if (Flag[i] == "3")
                        {

                            //dgr.DefaultCellStyle.ForeColor = Color.Blue;
                            dgr.Cells[2].Style = cstyle;
                        }
                        if (Flag[i] == "4")
                        {

                            //dgr.DefaultCellStyle.ForeColor = Color.Blue;

                            dgr.Cells[3].Style = cstyle;
                        }

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }

  • 相关阅读:
    centos7: 将nginx,php-fpm加入开机启动
    centos7: php7.2.9安装配置
    centos7: nginx安装配置
    linux编译安装mysql5.1.x
    docker删除镜像的时候报错--image has dependent child images
    数据库sql优化总结之2-百万级数据库优化方案+案例分析
    数据库sql优化总结之1-百万级数据库优化方案+案例分析
    MongoDB语法与现有关系型数据库SQL语法比较
    Redis和MongoDB的区别以及应用场景
    浏览器渲染基本原理(五):优化渲染性能
  • 原文地址:https://www.cnblogs.com/ok519/p/1558084.html
Copyright © 2011-2022 走看看