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) { } } }
时间: 2024-10-12 22:19:14