交替行颜色按列中的数字

问题描述 投票:0回答:1

我有一个带有数字的列,用于确定作业和后缀:

例:

|Jobnumber|Suffix| 
  x001       1 - white
  x001       2 - grey
  x001       2 - grey
  x001       3 - white
  x002       1  <---- where it would break the alternating color, Should be grey!
  x002       1 - should be grey
  x002       1 - should be grey
  x002       2 - should be white
  x002       2 - should be white
  x003       1 - should be grey

我将报告设置为接受一系列Jobnumbers和一系列Suffixes,因此每个Jobnumber都有一组按升序排序的后缀。我的表达式代码由不同的Suffix数字按颜色交替,但是当下一个JobnumberSuffix在报告中接下来时它会中断。

当下一组JobnumbersSuffixes出现在报告中时,如何让行仍按颜色交替?

reporting-services
1个回答
1
投票

如果您希望交替的行颜色忽略作业编号和后缀,则将表达式基于ROWNUMBER而不是后缀。

例如=IIF(ROWNUMBER(Nothing) MOD 2, "LightBlue", Nothing)

更新:基于修订的问题

可能有一种更优雅的方式,但以下应该有效。

首先要做的是转到报告属性并在报告中添加两个报告变量。添加值为AltBackColour1LastRownumber,其值为-1。关闭只读复选框enter image description here

接下来,单击Code选项卡添加以下功能。

Public Function BackColour (ByVal cuRowNumber AS Integer, ByVal lastJobNumber AS String, ByVal curJobNumber AS String, ByVal lastSuffix AS Integer, ByVal curSuffix AS Integer) as Integer
' Check if EITHER the job or suffix have changed, if so, switch the backcolour flag and update the report variable.

Dim switch as boolean
switch = ((lastJobNumber <> curJobNumber) or (lastSuffix <> curSuffix)) and cuRowNumber <> Report.Variables!LastRowNumber.Value

If Switch = true THEN 
    IF Report.Variables!AltBackColour.Value = 0 THEN 
        Report.Variables!AltBackColour.Value = 1 
    ELSE Report.Variables!AltBackColour.Value = 0
    END IF
End if

Report.Variables!LastRowNumber.Value = cuRowNumber

BackColour = Report.Variables!AltBackColour.Value 

End Function

最后,将行的BackgroundColor属性设置为以下表达式。

=IIF(
    Code.BackColour(
                    RowNumber(Nothing)
                    , Previous(Fields!JobNumber.Value)
                    , Fields!JobNumber.Value
                    , Previous(Fields!Suffix.Value)
                    , Fields!Suffix.Value
                    ) = 0
    , Nothing
    , "LightGreen"
    )

我用你的样本数据做了这个,得到了以下结果。

enter image description here

基本上,代码检查后缀的作业是否已更改,并在1和0之间切换标志以指示要使用的颜色。它还检查我们没有检查与以前相同的行。我们这样做是因为即使我们设置了行的backcolor属性,实际发生的是每个单元格获得的是backcolor属性集,这意味着为每个单元格调用代码并且将继续翻转标志。通过检查行是否已更改,我们绕过这个。

© www.soinside.com 2019 - 2024. All rights reserved.