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

            }

  • 相关阅读:
    FluorineFx:基于RSO(远程共享对象)的文本聊天室
    第一个十年,我从教师转行为web程序员,下一个十年呢?
    AS3中的单件(Singleton)模式
    数据结构C#版笔记双向链表(DbLinkList)
    FluorineFx:认证与授权
    FluorineFx:视频录制及回放(Flash/AS3环境)
    数据结构C#版笔记顺序表(SeqList)
    puremvc框架之hello world!
    flex中使用swc实现更好的界面代码分离
    puremvc框架之Command
  • 原文地址:https://www.cnblogs.com/ok519/p/1558084.html
Copyright © 2011-2022 走看看