PRINTING A ARRAYLIST(newbie)

C

cameljs18

private void printDocumentOrders_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
float linesPerPage = 0;
float yPosition = 1;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;

oleDbConnectionOrders.Open();
OleDbCommand commandMax = new OleDbCommand("SELECT MAX
(OrderID) FROM Orders", oleDbConnectionOrders);
OleDbCommand commandMin = new OleDbCommand("SELECT MIN
(OrderID) FROM Orders", oleDbConnectionOrders);
int maxID =
int.Parse((commandMax.ExecuteScalar()).ToString());
int minID =
int.Parse((commandMin.ExecuteScalar()).ToString());

System.Collections.ArrayList mylist = new
System.Collections.ArrayList();
for (int i = minID; i <= maxID; i++)
{
OleDbCommand command1 = new OleDbCommand("SELECT SUM
(UnitPrice*Quantity) FROM [Order Details] WHERE OrderID =" +
i.ToString() + "", oleDbConnectionOrders);

string total = command1.ExecuteScalar().ToString();
mylist.Add(total);

}
foreach (string mystring in mylist)
{
Font printFont = new Font("Times New Roman", 16,
FontStyle.Bold, GraphicsUnit.Pixel);
linesPerPage = e.MarginBounds.Height /
printFont.GetHeight(e.Graphics);
if (count <= linesPerPage)
{

SolidBrush myBrush2 = new SolidBrush(Color.Black);
yPosition = topMargin + (count *
printFont.GetHeight(e.Graphics));
e.Graphics.DrawString(mystring, printFont,
myBrush2, leftMargin, yPosition, new StringFormat());
count++;
}

}
This is my code.I need to print out all the integers in the arraylist
this works for the first page.
Please tell me how to make it continue onto the next page
 
P

Peter Duniho

[...]
This is my code.I need to print out all the integers in the arraylist
this works for the first page.
Please tell me how to make it continue onto the next page

You need two things:

1) You need to track how much text you've printed on each page, so
that on a subsequent call to your PrintPage handler, you can print the
right strings for that page.

2) You need to set the PrintPageEventArgs.HasMorePages property to
true in your PrintPage handler, unless you've printed the last page.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top