• 单元格着色


    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)
            {
                
            }
    
        }
    }
    
  • 相关阅读:
    iOS 内购出现 返回 NSCocoaErrorDomain ErrorCode: 4097
    《现代JavaScript教程》Arguments
    《现代JavaScript教程》Object
    Modern C++ 学习
    《现代 JavaScript 教程 》Symbol
    C++学习——format
    FcDigg 源码 asp.net 3.5
    springboot根据参数,调用不同的service接口(策略模式)
    EasyExcel导入导出excel
    【博客开通纪念】首度亮相暨发博动员大会
  • 原文地址:https://www.cnblogs.com/dyg540/p/5406365.html
Copyright © 2020-2023  润新知