Monday, March 19, 2012

Is it possible to change the operator of an expression at run time?

I have a report I have created in local mode, in a Winform ReportViewer using VB.net.

Is it possible to change the operator of an expression at run time? That is, I have a filter on a list that looks like this:

Expression: =Fields!InvNum.Value

Operator: =

Value: =Parameters!InvNum.Value

It is possible in code to change the operator from = to >= at the time I run the report? If so, what is the syntax? What I would like to do (don't know it is possible) is to have the operator set to >= at the time the the report is run and then set it back to = when a user selects a specific value for a Parameter for the report. Is this possible?

I suppose I can set it in the load event of the form that contains the ReportViewer, but if this is possible I have not been able to discover the syntax.

Anyone?

You can't change the filter operator at run-time. But you can change the filter expression to =IIF(<your condition>, Fields!InvNum.Value=Parameters!InvNum.Value, Fields!InvNum.Value>=Parameters!InvNum.Value), and the filter value to =true.|||

Thank you for responding.

It's not clear to me what you're saying. I mean I understand that you can change the filter expression as a whole (and not the filter operator) and I understand that you can do that with an Immediate IF statement, but where?

Are you saying that you can change the expression in code, at run time? If so, how and Where, specifically?

Or, are you saying that in the Filter tab of the List component that you can enter an IIF there? If so, what kind of value would I put in <your condition>?

It may be that I am asking a question that seems illogical to you, like "How is time?". But to me, what I am trying to do is pretty common. I am trying to figure out a way to bring lots of information into a report and then give the user the ability to whittle it down if he wants to.

|||

OK. I think I understand some of this. I created an additional string parameter for the report called IWantToSeeAllRows. I set the default value to Y. Then in the filter tab of the list, in the expression column I typed the following:

=IIF(Parameters!IWantAllRows.Value = "Y", Fields!InvNum.Value>=Parameters!InvNum.Value, Fields!InvNum.Value=Parameters!InvNum.Value)

After typing the above RS put an = character in the Operator column and <Blank> in the Value column of the grid in the filter tab.

When running the report I get an error of "Cannot compare data of types system boolean and system string. Please check the data type returned by the filter expression.

I am really guessing here as to where just exactly to place the code etc., but the documentation that I've found on the matter is not explicit for this particular issue. What am I missing?

|||

Most likely you changed the filter value expression to a constant value like TRUE (which is interpreted as string - hence the type mismatch).

Change the filter value expression to =True (which evalutes to a boolean)

-- Robert

No comments:

Post a Comment