zoukankan      html  css  js  c++  java
  • 15.8DataGridView选中行显示不同颜色

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace _15._8DataGridView显示不同颜色
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“csharpzxwDataSet.mytable001”中。您可以根据需要移动或删除它。
                this.mytable001TableAdapter.Fill(this.csharpzxwDataSet.mytable001);
    
            }
    
            private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
            {
                if (e.RowIndex >= dataGridView1.Rows.Count - 1) return;
                Color oldForeColor = new Color();
                Color oldBackColor = new Color();
                //object是所有类的基类为引用类型
                var row = dataGridView1.Rows[e.RowIndex];
                if (row == dataGridView1.CurrentRow)//判断是否是操作过的行
                {
                    if (row.DefaultCellStyle.ForeColor != Color.White)
                    {
                        oldForeColor = row.DefaultCellStyle.ForeColor;
                        row.DefaultCellStyle.ForeColor = Color.White;
                    }
                    if (row.DefaultCellStyle.BackColor != Color.Blue)
                    {
                        oldBackColor = row.DefaultCellStyle.BackColor;
                        row.DefaultCellStyle.BackColor = Color.Blue;
                    }
                }
                else
                {
                    row.DefaultCellStyle.ForeColor = oldForeColor;
                    row.DefaultCellStyle.BackColor = oldBackColor;
                }
            }
        }
    }
  • 相关阅读:
    IE8的parseInt
    powershell小工具
    判断请求是不是ajax
    常用命令行/批处理
    服务器导出服务器时间转换浏览器端时区
    用批处理批量编译多个解决方案(.sln)
    shell脚本批量调用git命令
    批处理(.bat)For命令使用
    360doc的文章不能复制的解决办法
    XSD笔记
  • 原文地址:https://www.cnblogs.com/zqyo2000z/p/5406331.html
Copyright © 2011-2022 走看看