简体   繁体   English

使用 ReportItem 集合的行可见性表达式不起作用

[英]Row visibility expression using ReportItem collection not working

This is major edit from the previous version of this question, which would hold little of value for future readers anyway.这是该问题先前版本的主要编辑,无论如何这对未来的读者来说几乎没有价值。

I have a report where I want to hide certain rows depending on the data in certain fields, but also be able to override this based on a parameter value.我有一个报告,我想根据某些字段中的数据隐藏某些行,但也能够根据参数值覆盖它。

So for my visibility (Hidden), I am using the following expression:因此,对于我的可见性(隐藏),我使用以下表达式:

=iif(CDbl(ReportItems!tbOEM1.Value) >= 20 Or CDbl(ReportItems!tbOEM2.Value) >= 20 Or CDbl(ReportItems!tbOEM3.Value) >= 20 Or Parameters!OEM20.Value.Equals(False)
,    False
,   True
)

Which I think should mean, if any of the 3 tbOEM fields are >= 20, then display the row.我认为这应该意味着,如果 3 个tbOEM字段中的任何一个 >= 20,则显示该行。 But if the user has selected False for the "OEM20" parameter (Boolean), display all the rows regardless of the values.但是,如果用户为“OEM20”参数(布尔值)选择了False ,则无论值如何,都将显示所有行。

However, when I run the report and choose True for the OEM20 parameter, No rows get displayed, even though I know that there are rows that have OEM values over 20.但是,当我运行报告并为 OEM20 参数选择True时,没有显示任何行,即使我知道有些行的 OEM 值超过 20。

To investigate, I added a background color expression to each of the tbOEM reportitems.为了进行调查,我为每个 tbOEM 报告项添加了背景颜色表达式。 Here is the background color expression for tbOEM1:这是 tbOEM1 的背景颜色表达式:

=iif(CDbl(ReportItems!tbOEM1.Value) >= 20
,   "Red"
,   "White"
)

When I run the report with False for the OEM20 parameter, I see all rows returned, and no fields are colored Red, even the ones that should be because they are tbOEM fields with a value >=20.当我为 OEM20 参数使用 False 运行报告时,我看到所有行都返回了,并且没有字段被涂成红色,即使是那些应该是因为它们是值 >=20 的 tbOEM 字段。

So I wonder if this is an order of execution issue where the value of the ReportItem is not yet known when setting visibility and background color?所以我想知道这是否是执行顺序问题,在设置可见性和背景颜色时 ReportItem 的值尚不知道? Is this known and documented anywhere?这在任何地方都知道并记录在案吗? I googled and couldn't find anything.我用谷歌搜索并找不到任何东西。

Or am I doing something else wrong that is fixable?还是我在做其他可以修复的错误?

I already know that a workaround is to use the datafield calculations that populate the tbOEM fields in the expressions, rather than the ReportItems collection.我已经知道一种解决方法是使用填充表达式中 tbOEM 字段的数据字段计算,而不是使用 ReportItems 集合。 So you needn't bother to tell me about this option.所以你不必费心告诉我这个选项。

Here's some things to try.这里有一些东西可以尝试。 Putting this as an answer as it will be too big for a comment.将此作为答案,因为它太大而无法发表评论。

I'm still thinking something weird is happening with type comparison/conversion.我仍然认为类型比较/转换正在发生一些奇怪的事情。

Maybe the tbOEM textboxes are strings with non-numeric characters (even just a space) so the CDbl conversion is failing, and thus failing the CDbl(ReportItems.tbOEM1.Value) >= 20 test even though it looks like it is above 20 when displayed as a string.也许tbOEM文本框是带有非数字字符(甚至只是一个空格)的字符串,因此CDbl转换失败,因此CDbl(ReportItems.tbOEM1.Value) >= 20测试失败,即使它看起来高于 20 时显示为字符串。 Given your background colour expression is also failing, this seems to be the case.鉴于您的背景颜色表达也失败了,这似乎是这种情况。 Let's use the Val expression for the comparison instead:让我们使用Val表达式进行比较:

Val(ReportItems!tbOEM1.Value) >= 20

Val doesn't give errors when converting to a numeric value, it just does the best it can and returns whatever number it finds. Val在转换为数值时不会出错,它只是尽其所能并返回它找到的任何数字。 Convert the field into the numeric value for display purposes as well as for the background colour expression so we see what the expression sees, not just the displayed text.将字段转换为用于显示目的的数值以及背景颜色表达式,以便我们看到表达式看到的内容,而不仅仅是显示的文本。 On your tbOEM1 textbox use these expressions for the following properties:在您的tbOEM1文本框上,将这些表达式用于以下属性:

Value价值

=Val(Fields!OEM1.Value)

Background.Color背景颜色

=iif(Val(ReportItems!tbOEM1.Value) >= 20, "Red", "White")

If this still fails (for example, the textbox no longer displays a value) then let's trim it first to get rid of any spaces: =Val(Trim(Fields.OEM1.Value))如果这仍然失败(例如,文本框不再显示值),那么让我们先修剪它以去除任何空格: =Val(Trim(Fields.OEM1.Value))

If the OEM1 field is a decimal value use 20.0 rather than 20 so it is comparing to a Double rather than an Integer in case something funky is happening with the implicit type conversion in the comparison.如果OEM1字段是十进制值,请使用20.0而不是20 ,因此它与 Double 而不是 Integer 进行比较,以防比较中的隐式类型转换发生一些奇怪的事情。

Okay, now hopefully the textboxes are displaying the correct number and the background is being coloured correctly.好的,现在希望文本框显示正确的数字并且背景颜色正确。 Now we just need to fix the Visibility.Hidden expression for the row.现在我们只需要修复行的Visibility.Hidden表达式。 I wouldn't use Value.Equals here as the parameter is already a boolean so we can just use it directly:我不会在这里使用Value.Equals因为参数已经是 boolean 所以我们可以直接使用它:

=iif(Val(ReportItems!tbOEM1.Value) >= 20 Or Val(ReportItems!tbOEM2.Value) >= 20 Or Val(ReportItems!tbOEM3.Value) >= 20 Or Not Parameters!OEM20.Value
    , False
    , True
)

This needs to be applied to the entire row by selecting the handle for the row on the left of the tablix, rather than applied to the textboxes directly.这需要通过选择 tablix 左侧行的句柄来应用于整行,而不是直接应用于文本框。

Of course, add the Trim function if the experiment above required it.当然,如果上面的实验需要,添加Trim function。

Good luck.祝你好运。 I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM