Page 1 of 1

Access data in BeginRenderEvent of report

Posted: Mon Feb 21, 2011 9:42 am
by Andreas Tastler
Hello

I want handle the visibility of a form by data content. The only event where this can be handeled is the BeginRenderEvent from report.
I noticed that there is no data at this time, because the Dictionary.Connect() method will be called later than the InvokeBeginRender() Method.
Data is always a recordset which will be registered after instantiating StiReport.
Could I run into any problem or is there a performance impact, if I use the following code in the BeforePrintEvent?

Code: Select all

Dictionary.Connect();
Form1.Visible = (Root.ID_Rechnung > 0);
Thank you
Andreas

Access data in BeginRenderEvent of report

Posted: Mon Feb 21, 2011 4:18 pm
by JorisWils
Hi Andreas

I wanted to show a form based on a condition too.

So ... here is what worked for me:
- form in the beginning of the report.
- make sure it is set to visible. (in order to have the events trigered )
- create a boolean to set visibility of the form.
- use the loadformevent of the form
I use this code:

Code: Select all

//First lets set the boolean to false. I don't want to show the report by default, only when a certain condition is met.
blnShowForm=false;

//Let's loop through the records in our table (table1)
foreach (Stimulsoft.Report.Dictionary.StiRow dataRow in table1.Rows)
{
        //When my ID-collumns contains a value that is lager then 10, I want to show my form.
	if ((int)dataRow["ID"]>10)
	{
		blnShowForm=true;
	}
}

if (!blnShowForm)
{
        //Now we know if we really want to disable the form.
        ((StiForm)sender).Visible=false;
}
It may not be ideal.... but hey... it works :-)

Access data in BeginRenderEvent of report

Posted: Mon Feb 21, 2011 11:37 pm
by Andreas Tastler
Hi Joris

Thank you for the tip. I just didn't realize that the form can be hidden in the OnLoad event of the form itself.

So I can move my code to the OnLoad event and everything is working fine.
Because the Form1 is generated into the code of the Report, it isn't even necessary to cast the event sender.

Code: Select all

Form1.Visible = (Root.ID_Rechnung > 0);
Thank you
Andreas