ListBox Report

I try to create a report using list box… I have run the listboxreport which is available in xojo example,.
While print the same , 5 rows are missing in every page.

Kindly help me out from this

Did you used OpenPrinter, OpenPrinterDialog functions ?
The idea is to set the page width/height.

Note: I never used Xojo Reports.

Also: printing a ListBox contents (no Xojo Reports), you have to issue the NextPage command when appropriate (so compute the number of Rows / Page, then issue next page [or PageNext…]).

[quote=290207:@Emile Schwarz]Did you used OpenPrinter, OpenPrinterDialog functions ?
The idea is to set the page width/height.

Note: I never used Xojo Reports.

Also: printing a ListBox contents (no Xojo Reports), you have to issue the NextPage command when appropriate (so compute the number of Rows / Page, then issue next page [or PageNext…]).[/quote]

Thanks for the response…

I have used OpenPrinterDialog function.
Can u please advice how and where to use Nextpage command.

Hi Pathma,

I will suppose you want to print a Listbox contents (not related to Xojo Reports).

you use the Graphics Reference (g), to print each cells of the Row, and when it is time, you issue a g.NextPage.

When is it time to issue a next page ?

You have to get the page height, divide it with the text (row/cell) height: you have a number of lines (of course, all lines are printed using the same height).

In the print loop, you have to have an Y value to print the Rows, you also use a Line_Index (for example) that you inc after printing a line, then you check that value with the number of line for each page (previous paragraph). If the current line is the last for this page, you issue a g.NextPage, else the program goes back to print the next line.

Is it clear now ?

In PrinterSetup, you can get the Page properties (and Printable area values).

You can use something like:

[code] Dim p As New PrinterSetup
Dim g As Graphics
Dim settings As String
Dim Printed_Lines As Integer // Indice of the printed line(s)
Dim Lines_By_Page As Integer // Number of lines for each page
Dim PA_Width As Integer // PrintArea Width
Dim PA_Height As Integer // PrintArea Height
Dim Row_Cnt As Integer // Number of Rows to print
Dim Row_Height As Integer // Row Heught (used as Y to print Rows)
Dim LoopIdx As Integer // Loop indice
Dim Line_Y As Integer // THe Y value

// Set the Printer Default Properties
p.Landscape = True // Remove these two lines if you want to print as Portrait.

If p.PageSetupDialog Then
g = OpenPrinterDialog§
End If

// Get the Printable Area width and height
PA_Width = p.Width
PA_Height = p.Height

// Compute the number of Line for each page
Lines_By_Page = PA_Height / LB.RowHeight // Height of the Listbox

// Number of Row to print
Row_Cnt = LB.ListCount - 1

// Get the Row Height
Row_Height = LB.RowHeight

// Set the Y start
Line_Y = Row_Height

// Now loop thru the Listbox to print the Rows
For LoopIdx = 0 To Row_Cnt
// Set the Print Row / Cells & Tab values process here
g.DrawString(LB.Cell(LoopIdx,-1), 0,Line_Y, PA_Width)

// Did we reach the page bottom ?
If Printed_Lines >= Lines_By_Page Then
  // YES !
  
  // Reset Line_Y
  Line_Y = Row_Height
  
  // Reset the value
  Printed_Lines = 1
  
  // Issue a Page Feed
  g.NextPage
  
Else
  // NO
  
  // Inc Line_Y value
  Line_Y = Line_Y + Row_Height
  
  // Add 1 to the number of printed pages
  Printed_Lines = Printed_Lines + 1
End If

If UserCancelled Then Exit

Next[/code]

LB in the code refers to the Listbox you want to print.

Of course, you can check the pages to print (From x to y), use a simple g.DrawString to draw each row or draw each cell of a Row using a Tab value, etc.

I just tested it (open the pdf in Preview/ OS X): it works fine.

PS: you can use the Print to PDF in both OS X and Windows 10 (with its inluded feature) or previous version: download a PDF virtual printer; doing that will avoid waste of paper 'till you feel your printing code works :wink:

You can also store the settings for later re-use.

Thanks Emile Schwarz for detailed explanation…
Above mentioned code was working fine to me also…
But I was unable to use the same setup in xojo report…

Did you checked Xojo Reports Examples ?

Also: what did you miss in my example ?