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

            }

  • 相关阅读:
    hdu 5965 扫雷
    51nod 1441 士兵的数字游戏 (素数处理
    51nod 1453抽彩球
    51nod 1255 字典序最小的子序列
    codeforces 948A
    Splay 伸展树 bzoj3224 bzoj3223
    2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest C(gym/101142 C)
    2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest F(gym/101142 F)
    2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest G(gym/101142 G)
    Educational Codeforces Round 32 E 巨型背包
  • 原文地址:https://www.cnblogs.com/ok519/p/1558084.html
Copyright © 2020-2023  润新知