码迷,mamicode.com
首页 > 其他好文 > 详细

单元格着色

时间:2016-04-19 00:07:44      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

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

    }
}

 

单元格着色

标签:

原文地址:http://www.cnblogs.com/dyg540/p/5406365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!