• 根据条件单元格的值改变单元格的显示色块和文字颜色等属性。


            #region 设置单元格样式(设置背景色)
            /// <summary>
            /// 设置单元格样式(设置背景色)
            /// </summary>
            /// <param name="gridView"></param>
            /// <param name="fieldName">"States";"OrderStatus"</param>
            /// <param name="color">Color.Green;Color.FromArgb(30, 119, 194)</param>
            /// <param name="expression">表达式(条件),如[LowPrice] > [PrevPrice];"AuditStatus=='已审核'";[Name] != ?</param>
            public static void SetStyleFormatCondition(this GridView gridView, string fieldName, Color color, string expression)
            {
                GridColumn gc = gridView.Columns[fieldName];
                StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition();
                condition1.Column = gc;
                condition1.Appearance.BackColor = color;
                condition1.Appearance.Options.UseBackColor = true;
                condition1.Condition = FormatConditionEnum.Expression;
                condition1.Expression = expression;
                gridView.FormatConditions.Add(condition1);
            }
            /// <summary>
            /// 设置单元格样式(设置背景色)
            /// </summary>
            /// <param name="gridView"></param>
            /// <param name="fieldName">"States";"OrderStatus"</param>
            /// <param name="color">Color.Green;Color.FromArgb(30, 119, 194)</param>
            /// <param name="condition">FormatConditionEnum.Equal;None,Equal,NotEqual,Between,NotBetween,Less,Greater,GreaterOrEqual,LessOrEqual,Expression,</param>
            /// <param name="conditionValue1">0;"已提交"</param>
            /// <param name="conditionValue2">用于两个值取区间</param>
            public static void SetStyleFormatCondition(this GridView gridView, string fieldName, Color color, FormatConditionEnum condition, object conditionValue1, object conditionValue2)
            {
                GridColumn gc = gridView.Columns[fieldName];
                StyleFormatCondition condition1;
                if (conditionValue2 == null)
                {
                    condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null,
                        conditionValue1);
                }
                else
                {
                    condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null,
                        conditionValue1, conditionValue2);
                }
                condition1.Appearance.BackColor = color;
                condition1.Appearance.Options.UseBackColor = true;
                gridView.FormatConditions.Add(condition1);
            }
            #endregion
    
    
            #region 设置单元格(字体颜色)
            /// <summary>
            /// 设置单元格(字体颜色)
            /// </summary>
            /// <param name="gridView"></param>
            /// <param name="fieldName">"States";"OrderStatus"</param>
            /// <param name="color">Color.Green;Color.FromArgb(30, 119, 194)</param>
            /// <param name="expression">表达式(条件),如[LowPrice] > [PrevPrice];"AuditStatus=='已审核'";[Name] != ?</param>
            public static void SetStyleFormatFontCondition(this GridView gridView, string fieldName, Color color, string expression)
            {
                GridColumn gc = gridView.Columns[fieldName];
                StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition();
                condition1.Column = gc;
                condition1.Appearance.ForeColor = color;
                condition1.Appearance.Options.UseForeColor = true;
                condition1.Appearance.Options.UseTextOptions = true;
                condition1.Condition = FormatConditionEnum.Expression;
                condition1.Expression = expression;
                gridView.FormatConditions.Add(condition1);
            }
            /// <summary>
            /// 设置单元格(字体颜色)
            /// </summary>
            /// <param name="gridView"></param>
            /// <param name="fieldName">"States";"OrderStatus"</param>
            /// <param name="color">Color.Green;Color.FromArgb(30, 119, 194)</param>
            /// <param name="condition">FormatConditionEnum.Equal;FormatConditionEnum.GreaterOrEqual</param>
            /// <param name="conditionValue1">0;"已提交"</param>
            /// <param name="conditionValue2">用于与conditionValue1求区间范围</param>
            public static void SetStyleFormatFontCondition(this GridView gridView, string fieldName, Color color, FormatConditionEnum condition, object conditionValue1,object conditionValue2 = null)
            {
                GridColumn gc = gridView.Columns[fieldName];
                StyleFormatCondition condition1;
                if (conditionValue2 == null)
                {
                    condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null,
                        conditionValue1);
                }
                else
                {
                    condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null,
                        conditionValue1, conditionValue2);
                }
                condition1.Appearance.ForeColor = color;
                condition1.Appearance.Options.UseForeColor = true;
                condition1.Appearance.Options.UseTextOptions = true;
                gridView.FormatConditions.Add(condition1);
            }
            #endregion

    设置列背景色  https://www.cnblogs.com/MuNet/p/5736172.html
    Devexpress GridView 数据根据不同条件格式化显示色块和文字颜色  http://www.zhimengzhe.com/asp_netjiaocheng/161557.html
    Devexpress Winform Gridcontrol 中根据条件单元格的值改变单元格的颜色等属性。  http://www.lxway.com/668495256.htm

    condition1.Expression = "[Name] != ?"; //Name字段不为空

    cn.Appearance.BackColor = Color.Green;

  • 相关阅读:
    Selenium WebDriver使用IE浏览器(转)
    webdriver调用ie浏览器报错
    webdriver调用chrome浏览器
    WebDriver 调用ie浏览器报错(转)
    Eclipse上安装GIT插件EGit及使用(转)
    webDriver 退出浏览器(转)
    JMeter csv文件参数化
    不同目录存在相同名称的py文件,执行时,报错的解决方法
    python+requests传两种参数体
    JMeter 请求参数
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/8178015.html
Copyright © 2020-2023  润新知