"New page after" by code

Stimulsoft Reports.NET discussion
Post Reply
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

Hi.
Is there a way to set "New page after" by code,I need to create a report where user can select this.
Thanks.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"New page after" by code

Post by Edward »

Hi.

There is a method for starting of the new page in the EngineV2:

Engine.NewPage();

You can call it from any event inside the report.

Thank you.
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

Thanks Edward,this works !!!
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"New page after" by code

Post by Edward »

Please let us know if we could assist you any further.

Thank you.
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

Thanks Edward
I'm using this code in GroupFooter "After Print" event

Code: Select all

If var_NewPageGrp=1 Then Engine.NewPage()
It works fine but it gives me +1 page blank at the end.This is normal, I need a more complex validaton for last group of data but how I'll do that.
Thanks a lot !
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"New page after" by code

Post by Edward »

Hi

You can delete the last page from the collection of rendered pages in case if it is the empty page, for example. So you write the following code in the EndRender event of the report:

Code: Select all

StiPage lastPage = this.RenderedPages.Items(this.RenderedPages.Count-1);
if (lastPage.GetComponents().Count == 0)
{
	this.RenderedPages.RemoveAt(this.RenderedPages.Count-1);
}
 
Thank you.
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

I can't convert this code to VB,I got errors ( error BC30469: Reference to a non-shared member requires an object reference.) and report is not compiled,I've tried this :

Code: Select all

Dim lastPage As New Stimulsoft.Report.Components.StiPage
If lastPage.GetComponents().Count = 0 Then
   Report.RenderedPages.RemoveAt(Report.RenderedPages.Count-1)
End If
My version is 2008.2
Thanks.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"New page after" by code

Post by Edward »

Please modify the code as follows:

Dim lastPage As Stimulsoft.Report.Components.StiPage = Me.RenderedPages.Items(Me.RenderedPages.Count-1)
If lastPage.GetComponents().Count = 0 Then
Me.RenderedPages.RemoveAt(Me.RenderedPages.Count-1)
End If

And there is a report in the attachment.

Thank you.
Attachments
158.BeforePrintEvent.mrt
(4.84 KiB) Downloaded 398 times
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

Thanks Edward
This time report is compiled but when it is run I got
"Exception has been thrown of target of an invocation"
If I remove the event code, report works as before.
Thanks

mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

"New page after" by code

Post by mrapi »

Thanks Eduard,it works.
One mention : page footer elements like text objects ( for page numbering ) are also counted in .GetComponents().Count

Post Reply