【问题标题】:Change of background color in table column based on condition in Reporting根据报告中的条件更改表格列中的背景颜色
【发布时间】:2017-02-16 20:26:16
【问题描述】:

我已经创建了表格,我需要根据该列第一行的值更改列的背景颜色。

如果特定列的第一行值为 0 或连字符(-),我需要更改 1.) 该列行的背景颜色为灰色,否则为透明 2.) 该特定列的行中的所有值都应该用连字符(-)填充。

以下是我尝试过的,但无法达到我的要求。

注意:我应该使用 XRTableCell 等报告 API 控件。也欢迎其他想法来实现这一点。

using System;
using System.Drawing;
using DevExpress.XtraReports.UI;

private void tableCell12_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e)
{
    XRTableCell tableCell = sender as XRTableCell;
    double bancoAtivo = Convert.ToDouble(tableCell.Report.GetCurrentColumnValue("Campaign Count"));

    if (bancoAtivo = 0)
    {
        tableCell.BackColor = Color.Grey;
    }
    else
    {
        tableCell.BackColor = Color.Transparent;
    }
}

【问题讨论】:

  • 你的代码看起来是不是一个错字。根据你的实现方式,你的代码应该可以正常工作,但列名不能包含空格,并且 if 语句看起来不错。

标签: c# reporting-services devexpress


【解决方案1】:

您的实现是正确的,但您对问题的描述存在一些差距。如果您只想更改单列单元格的颜色,我也建议您使用相同的方法。

处理XRTableCell.BeforePrint 事件并更改背景色 或发送者对象的 Text 属性。要获取处理后的记录, 使用XtraReportBase.GetCurrentRowXtraReport.GetCurrentColumnValue 方法。

您可以使用 Conditional Formatting 帮助文章中描述的 FormattingRules 或处理相应单元格的 BeforePrint 事件,并根据处理后的值设置发送者对象的 BackColor。

参考这些:
Customize the Report Appearance
Changing background of XRTableCell according to color value in data column.
How to change the XRTable background color?

【讨论】:

  • 这里我需要检查数据列的第一行,如何检查或放置条件,以便如果第一行为零或列中的连字符,我需要将整列变灰,然后用连字符替换零整列。在您的链接中,我得到了更改颜色的代码,我需要根据第一行列的条件更改颜色。
猜你喜欢
  • 2015-01-14
  • 2011-04-23
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多