• 单元格着色


    using DevExpress.XtraGrid.Views.Grid.ViewInfo;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Win01
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                string connstr = ConfigurationSettings.AppSettings["connstr"].ToString();
                SqlConnection conn = new SqlConnection(connstr);
    
                string sql = "select * from t_user";
    
                DataTable dt = new DataTable();
                SqlDataAdapter dr = new SqlDataAdapter(sql, conn);
                dr.Fill(dt);
    
                gridControl1.DataSource = dt;
    
    
    
            }
    
            private void gvlist_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
            {
                if (e.Column.FieldName == "flag")
                {
                    GridCellInfo GridCellInfo = e.Cell as GridCellInfo;
                    if (GridCellInfo.IsDataCell && GridCellInfo.CellValue.ToString() == "n")
                    {
                        e.Appearance.BackColor = Color.Yellow;
                    }
                }
    
            }
            private void gvlist_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
            {
    
                if (gvlist.GetDataRow(e.RowHandle) == null) return;
                if (gvlist.GetDataRow(e.RowHandle)["flag"].ToString() == "n")
                {
                    //该行数据的该列的值为1时,其背景色为gray
                    e.Appearance.BackColor = Color.Red;
                }
                //else
                //{
                //    e.Appearance.BackColor = Color.Blue;
                //}
                if (e.RowHandle == gvlist.FocusedRowHandle)
                {
                    e.Appearance.ForeColor = Color.White;
                    e.Appearance.BackColor = Color.RoyalBlue;
    
                }
            }
    
            private void gridControl1_CausesValidationChanged(object sender, EventArgs e)
            {
                
            }
    
        }
    }
    
  • 相关阅读:
    vue keep-alive 缓存组件
    媒体查询手机屏幕横屏竖屏
    手机端rem
    vue技术栈导出pdf
    判断是否为微信浏览器还是支付宝浏览器
    当前时间和倒计时效果
    npm install 报错node-sass模块找不到
    Lenovo System x3650 设置管理接口地址
    Python之excel文件追加内容
    python3 文件操作
  • 原文地址:https://www.cnblogs.com/dyg540/p/5406365.html
Copyright © 2020-2023  润新知