Get vertical page position (i.e. top) of databand?

Stimulsoft Reports.WEB discussion
Post Reply
phoare
Posts: 3
Joined: Sun Jan 31, 2021 12:42 pm

Get vertical page position (i.e. top) of databand?

Post by phoare »

We have a report where we want to ensure that we have a page break before the last record if it's otherwise going to get printed below a certain place on the page.

Suppose we can fit 4 records on a page. Printing a report with 3 records would give us one page, a report with 4 records would give us two pages (first page records 1-3, second page record 4), a report with 5 records would give us records 1-4 on the first page, record 5 on the next page, 8 records would give 1-4 on first page, 5-7 on next page, record 8 on third page, etc.

We did have that working fine with a BeforePrint event on the databand to say that if we were about to print the last record and if the number of records mod 4 was zero, then to do an Engine.NewPage().

But now we're in the position that due to varying data, sometimes a page may hold 3 records, sometimes 4 or sometimes 5. Each record takes the same vertical height, it's just headers and footers than may vary.

So back to the opening problem - what we really want to do is to amend our BeforePrint event to say that if the databand position on the page is more than a certain way down the page, then we do our Engine.NewPage(). Or, of course, to do an AfterPrint event and test if we've just handled the last-but-one record.

But we can't work out how to get the "y" position of where we are on the page, or the Top of the databand?
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Get vertical page position (i.e. top) of databand?

Post by Lech Kulikowski »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
phoare
Posts: 3
Joined: Sun Jan 31, 2021 12:42 pm

Re: Get vertical page position (i.e. top) of databand?

Post by phoare »

Don't know if we're thinking about this the right way. To put the problem in a different way, it's essential for us that the Report Summary band does not appear on it's own - that we don't end up with a page break between the last instance of the databand and the report summary. In other words if the last record on the data band fits on the page but then there's no room for the report summary, we want that last record of the data band pushed onto a new page (even though it would have fitted) and then followed by the report summary.

Thought we might have hit upon a solution by working out the height of the report summary, working that out as a percentage of the page, and then having a calculated expression on the "Break If Less Than" property to return 100 if not the last page and that calculated percentage if it is... but the report designer doesn't allow that property to be an expression.

Would that approach work if we do that in code? Had a try but not convinced we were handling this in the right events.

Thanks in advance for any suggestions or advice.
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Get vertical page position (i.e. top) of databand?

Post by Lech Kulikowski »

Hello,

You can use DoublePass, in the first pass, you can check all necessary conditions to show necessary elements and in the second pass, set necessary properties.

Thank you.
phoare
Posts: 3
Joined: Sun Jan 31, 2021 12:42 pm

Re: Get vertical page position (i.e. top) of databand?

Post by phoare »

Many thanks for the response - only could you expand on what you had in mind?

We did think that turning double pass on and putting something like the following in the BeforePrint event on the databand would work... but it didn't:

Code: Select all

if ((Count(ITEM) == Line) && !IsLastPage) { // if we're doing the last ITEM and we're not on the last page, throw a break to ensure what follows stays together with this last ITEM
	Engine.NewPage();
}
Is the databand's BeforePrint the wrong place to do this? Or is that now how IsLastPage / Double Pass works?

That would have been a very elegant way of doing what we need if it had worked :)
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Get vertical page position (i.e. top) of databand?

Post by Lech Kulikowski »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
Post Reply