Cannot set Variables at runtime though a c# application

Stimulsoft Reports.NET discussion
Post Reply
mathat1970
Posts: 6
Joined: Wed Jan 05, 2011 5:05 pm

Cannot set Variables at runtime though a c# application

Post by mathat1970 »

I am trying to allocate a value for Report Designer variable from a C#.net application.

The value is not however being displayed ... either I am referenceing the field incorrectly or the value cannot be allocated at runtime in this manner.

Can someone please confirm that this can be done or not ?

And if it can be done I would appreciate some pointers.

Please find below the snippets of from within my C# application

Code: Select all

Dictionary ReportVariableValue;
....
foreach(KeyValuePair pair in ReportVariableValue)
{
    report.Dictionary.Variables[pair.Key].Value = pair.Value;
}
Precondions:

* ReportVariableValue has valid data i.e. pair.Key is the variable name in the stumulsoft designer e.g. "VirtualPageNo" and pair.Value has a valid string e.g. "1"
* Report is compiled

Postconditions:

* I have checked through debug mode and determined that report.Dictionary.Variables[] has the correct values
* I then do an export to a PDF .... the report is displayed as a PDF but the Variables I have changed have not been set the runtime values.

Martin Hart Turner
Posts: 66
Joined: Wed Apr 04, 2007 3:32 am
Location: Spain

Cannot set Variables at runtime though a c# application

Post by Martin Hart Turner »

Hi:

I have also had lots of fun with this topic :amazed:

In the preconditions you say the report is compiled, but how do you check this?

What I am trying to say is that there are two variables you should be checking:
- report.IsCompiled
- report.NeedsCompiling

If the report IsCompiled and NeedsCompiling is false you should be okay to set the variables and they should work as expected.

HTH,
Martin.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Cannot set Variables at runtime though a c# application

Post by Alex K. »

Hello,

If report not compiled then you can use the following code:

Code: Select all

report.Dictionary.Variables[pair.Key].Value = pair.Value;
else

Code: Select all

report[pair.Key] = pair.Value;
In some cases, you must create a report without compilation. For this purpose the NeedsCompilling property was added.

Thank you.
mathat1970
Posts: 6
Joined: Wed Jan 05, 2011 5:05 pm

Cannot set Variables at runtime though a c# application

Post by mathat1970 »

Thankyou both for your help and knowledge of the system.

I got it work with the code sample supplied i.e.

Code: Select all

report[pair.Key] = pair.Value;
I also now have a better understanding.

thanks again.



Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Cannot set Variables at runtime though a c# application

Post by Alex K. »

Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.
Post Reply