How to identify the last datarow on page

Stimulsoft Reports.NET discussion
AndreasB_CH
Posts: 7
Joined: Fri Jul 02, 2021 1:18 pm

How to identify the last datarow on page

Post by AndreasB_CH »

I have a databand with lines of size 1 between the rows. Sometimes my data goes over more than one page and I want to draw a line with size 2 under the last row of the page instead of the line with size 1.
Is there any way to solve this within Designer ?
Lech Kulikowski
Posts: 6237
Joined: Tue Mar 20, 2018 5:34 am

Re: How to identify the last datarow on page

Post by Lech Kulikowski »

Hello,

Please check the IsLastPage from system variables (Returns true, if, in the current moment, the last page of a report is printed. For correct calculation of a variable it is required to execute two passes.)

Thank you.
ulli82
Posts: 47
Joined: Tue Jul 06, 2021 6:46 am

Re: How to identify the last datarow on page

Post by ulli82 »

Hi,

are you interested in item of last page or last item on each page?

If "last item on each page": Try to change the rendered components. For this you should use the Report.EndRender event and loop through all RenderedPages of the report and through their components, starting with the last one and stop the loop the first time you find the corresponding component.

Regards
AndreasB_CH
Posts: 7
Joined: Fri Jul 02, 2021 1:18 pm

Re: How to identify the last datarow on page

Post by AndreasB_CH »

Maybe I didn't get it right...
IsLastPage is true on the first record of the last page (independant from the number of passes).

I nead a "true" when I reach the last record of the current page to make a proper visual termination of the table.

Example: I have a report where the data (60 rows) spreads over three pages, so there are 20 lines per page from the same source (and within the same DataBand).
When I come to the 20th row, I need to know it's the last row of this page (and not the last page, so your hint is usefull anyways).
Unfortunately the rows can grow in hight, so the number of rows per page is dynamic (simply counting is not an option).
Lech Kulikowski
Posts: 6237
Joined: Tue Mar 20, 2018 5:34 am

Re: How to identify the last datarow on page

Post by Lech Kulikowski »

Hello,

There is no standard solution.
As a way, you can try to use Double Pass in first-pass check page counts and rows by pages and in the second set the necessary changes in events.

Thank you.
ulli82
Posts: 47
Joined: Tue Jul 06, 2021 6:46 am

Re: How to identify the last datarow on page

Post by ulli82 »

Has anyone read my proposed solution? It will work for sure. We are using such adaptions in our reports too...
AndreasB_CH
Posts: 7
Joined: Fri Jul 02, 2021 1:18 pm

Re: How to identify the last datarow on page

Post by AndreasB_CH »

ulli82 wrote: Thu Jul 08, 2021 6:36 am Has anyone read my proposed solution? It will work for sure. We are using such adaptions in our reports too...
Yes, I read it, but didn't understand ;-)
I think I get it now, I will try to implement it.

Thank you!!
AndreasB_CH
Posts: 7
Joined: Fri Jul 02, 2021 1:18 pm

Re: How to identify the last datarow on page

Post by AndreasB_CH »

Lech Kulikowski wrote: Wed Jul 07, 2021 9:25 pm As a way, you can try to use Double Pass in first-pass check page counts and rows by pages and in the second set the necessary changes in events.
My knowledge of double pass is really poor by now, but this could be an opportunity to change it.
I will try your solution, too.

Thanks a lot!
Lech Kulikowski
Posts: 6237
Joined: Tue Mar 20, 2018 5:34 am

Re: How to identify the last datarow on page

Post by Lech Kulikowski »

Hello,

You are welcome.
ulli82
Posts: 47
Joined: Tue Jul 06, 2021 6:46 am

Re: How to identify the last datarow on page

Post by ulli82 »

Here is a small sample code for event Report.EndRender

Code: Select all

StiReport report = sender as StiReport;
if (report == null)
	return;

// loop through all rendered pages
foreach (StiPage page in report.RenderedPages)
{
	// loop through all rendered elements on each page, starting with the last one
	for (int i = page.Components.Count - 1; i > 0; i--)
	{
		StiComponent comp = page.Components[i];
		
		if (comp.Name != "NameOfDataBand")	// ignore all other elements
			continue;

		IStiBorder border = comp as IStiBorder;	// ensure, element can have borders
		if (border == null)
			break;

		border.Border.Size = 2;	// change border line width
		break;	// stop loop through components -> only last databand of each page will be changed
	}
}
Post Reply