zoukankan      html  css  js  c++  java
  • Devexpress GridView 数据根据不同条件格式化显示色块和文字颜色

    1.色块和文字颜色方法

    /// <summary>
    /// 设置单元格样式(色块)
    /// </summary>
    /// <param name="gc">Devexpress GridView </param>
    /// <param name="color">颜色</param>
    /// <param name="expression">表达式(条件)</param>
    /// <returns></returns>
    protected virtual StyleFormatCondition SetStyleFormatCondition(GridColumn gc, Color color, string expression)
    {
    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;
    return condition1;
    }

    /// <summary>
    /// 设置单元格(字体颜色)
    /// </summary>
    /// <param name="gc">Devexpress GridView</param>
    /// <param name="color">颜色</param>
    /// <param name="expression">表达式(条件)</param>
    /// <returns></returns>
    protected virtual StyleFormatCondition SetStyleFormatFontCondition(GridColumn gc, Color color, string expression)
    {
    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;
    return condition1;
    }

    2.开始调用

    gvData.FormatConditions.Add(SetStyleFormatCondition(gvData.Columns["AuditStatus"], Color.FromArgb(56, 173, 40), "AuditStatus=='已审核'"));//审核状态(色块)

    gvData.FormatConditions.Add(SetStyleFormatFontCondition(gvData.Columns["OrderStatus"], Color.FromArgb(30, 119, 194), "OrderStatus=='未完成'"));//执行状态(文字颜色)

    执行结果:

  • 相关阅读:
    c++ exports def文件
    对比WDCP面板与AMH面板的区别与选择
    阿里云服务器配置 SVN 服务器与生产站点同步
    linux-Centos7安装python3并与python2共存
    oracle数据库定时任务dbms_job的用法详解
    AnyRobot
    spring mvc activemq
    kafka 查看队列信息
    json多态序列化
    CentOS7.x使用overlay文件系统
  • 原文地址:https://www.cnblogs.com/qq-xiao/p/6094405.html
Copyright © 2011-2022 走看看