zoukankan      html  css  js  c++  java
  • 单元格着色

    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)
            {
                
            }
    
        }
    }
    
  • 相关阅读:
    关于global和$GLOBALS[]的一些实践
    java环境配置的新手教程
    echart图表 resize()方法使用
    使用git上传下载项目
    windows 系统新建 vue 项目的坑
    Java版求1000以内的完全数
    Java版经典兔子繁殖迭代问题——斐波那契(Fibonacci)数列
    Java版冒泡排序和选择排序
    AngularJS 动画总结
    Mac下sublime text 的“package control”安装
  • 原文地址:https://www.cnblogs.com/dyg540/p/5406365.html
Copyright © 2011-2022 走看看