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);
                }

            }

  • 相关阅读:
    greybox关闭/刷新父窗口
    C# 获取文件编码
    框架页,URL中文参数乱码
    用来代替SQLSERVERAGENT的VBS脚本。
    jQuery的radio,checkbox,select操作
    mssql 的sp_help好难看
    如何判断网通、电信、铁通IP地址分配段
    IE8取不到 select 的option值
    如何识别当前的 SQL Server 版本号以及对应的产品级别
    控诉我的电脑
  • 原文地址:https://www.cnblogs.com/ok519/p/1558084.html
Copyright © 2011-2022 走看看