2017-02-16 51 views
0

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

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

下面是我试过的,但不能达到我的要求。

注意:我应该使用像XRTableCell这样的Reporting 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; 
    } 
} 
+0

难道不是你的代码看起来像一个错字。您的代码应该做工精细根据你实现,但列名不能包含空格,如果路声明看起来不错。 –

回答

0

您的实施方案是正确的,但您在描述该问题时存在一些空白。如果您只是想更改单列单元格的颜色,我也建议您使用相同的方法。

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

既可以使用FormattingRules作为Conditional Formatting帮助文章中描述或处理BeforePrint事件相应的单元,并设置背景色为基于经处理的值的发送者对象。

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

+0

这里我需要检查数据列的第一行,如何检查或放置条件,以便如果第一行为零或在列中显示,我需要灰色整列,然后用连字符替换整列。在你的链接中,我得到了改变颜色的代码,我需要根据第一行的条件改变颜色。 – daisy