How to modify a designer generated report at runtime?

Stimulsoft Reports.NET discussion
Post Reply
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

How to modify a designer generated report at runtime?

Post by haarrrgh »

In addition to my problem with modifying an image at runtime (here), I seem to have a general problem understanding how to modify anything at all in code at runtime.

I just tried it with a textbox:

Code: Select all

StiReport rep = new StiReport();
rep.Load("test.mrt");

DataSet ds = new DataSet();
(...) // fill Dataset

rep.RegData(ds);

rep.Compile();

foreach (object comp in rep.CompiledReport.GetComponents())
{
    if (comp.GetType() == typeof(StiText))
    {
        StiText tmp = new StiText();
        tmp = (StiText)comp;

        if (tmp.Name == "TestTextbox")
        {
            tmp.Text = tmp.Text += " (Test)";
        }
    }
}
rep.Render();

rep.ExportDocument(StiExportFormat.Pdf, @"c:\test.pdf");
The code compiles and runs, but it does nothing.
I wrote a text into the TestTextbox at designtime, but at runtime tmp.Text is empty.
My code appends the string to it (so it contains " (Test)" then), but on the exported report there is only the text that I set at design time.

I'm completely new at Stimulsoft Reports - can someone explain to me how to do it right?

We are very likely to buy Stimulsoft Reports, as soon we made sure that it can do everything that we need.
Manipulating images and text at runtime is the last thing that's missing.

Thank you!
Anton Lozovskiy
Posts: 135
Joined: Tue Aug 11, 2009 9:38 am

How to modify a designer generated report at runtime?

Post by Anton Lozovskiy »

Hello,

We created a simple example demonstrating the different ways to solve your problem.

Thank you.
Attachments
394.WindowsApplication1.zip
(316.48 KiB) Downloaded 318 times
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

How to modify a designer generated report at runtime?

Post by haarrrgh »

Thank you very much, that works perfectly!

You showed me two different ways to do the same thing - manipulate before rendering and manipulate after rendering.
Is there any difference, is one way better than the other?

I noticed that the following only works if I do it before rendering:

Code: Select all

if (comp.Name == "PageNumberTextBox")
{
    ((StiText)comp).Text = "Page {PageNumber} of {TotalPageCount}";
}
(I understand why - when I render first, the variables are already filled with the real page numbers, so when I set the text at this moment, the page numbers won't get filled again)

So I think manipulating before rendering is better, right?
Post Reply