C# GridView 自定义单元格的背景色
作者:C/S框架网  发布日期:2012/03/07 21:31:41
  C# GridView 自定义单元格的背景色


如下图所示,当货品的颜色栏位没有输入数据,单元格设置为红色。

贴图图片


非常简单,在需要在GridView.RowCellStyle事件内处理。


C# Code:

   //定义一组颜色样式

        AppearanceDefault appError = new AppearanceDefault(Color.White, Color.LightCoral, Color.Empty, Color.Red, LinearGradientMode.ForwardDiagonal);

 

        private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)

        {

            object val = gridView1.GetRowCellValue(e.RowHandle, e.Column);

 

            //如果货品的颜色为空值,单元格设置为红色

            if ((e.Column.FieldName == "ColorCode") && (String.IsNullOrEmpty(val.ToString())))

            {

                AppearanceHelper.Apply(e.Appearance, appError);//显示自己定义样式

            }

 

        }



上一篇 下一篇