Hi everyone,
i am attempting to print data in my Datatable. I have 6 columns with 60 rows of data in total.
I have managed to produce a print but some problems. For one it does not detect that there are more rows that the page can take, so i only see about 25 rows while the rest have gone to oblivion. I did however do some work on detecting weather it needs to print more pages and it does show correct amount of pages in the Preview, however it seems to just duplicating the first page.
First: I need to limit rows printed to about 20 rows of per page (with column names).
Second: I need to see all data from Datatable correctly printed on each page (continuing from page 1 to page 2 to page 3) which would make it to 60.
Third: Well at this stage i cannot even see the footer... but it should be printed on each page.
Here is my code so far:
private void document_PrintPage(object sender, PrintPageEventArgs e)
{
string header = "Master List " + CI.getDateTime("dd/MM/yyyy HH:mm");
string footer = string.Empty;
int columnCount = tmp_Table.Columns.Count;
int maxRows = tmp_Table.Rows.Count;
using (Graphics g = e.Graphics)
{
Brush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(brush);
Font font = new Font("Arial", 10);
SizeF size;
int x = 0, y = 0, width = 130;
float xPadding;
size = g.MeasureString(header, font);
xPadding = (width - size.Width) / 2;
g.DrawString(header, font, brush, x + 250, y + 5);
x = 0;
y += 30;
foreach (DataColumn column in tmp_Table.Columns)
{
size = g.MeasureString(column.ColumnName, font);
xPadding = (width - size.Width) / 2;
g.DrawString(column.ColumnName, font, brush, x + xPadding, y + 5);
x += width;
}
x = 0;
y += 30;
foreach (DataRow row in tmp_Table.Rows)
{
rowcount++;
for (int i = 0; i < columnCount; i++)
{
size = g.MeasureString(row[i].ToString(), font);
xPadding = (width - size.Width) / 2;
g.DrawString(row[i].ToString(), font, brush, x + xPadding, y + 5);
x += width;
}
e.HasMorePages = rowcount - 1 < maxRows;
x = 0;
y += 30;
}
footer = "Total: " + maxRows + " |Signed:..........................";
size = g.MeasureString(footer, font);
xPadding = (width - size.Width) / 2;
g.DrawString(footer, font, brush, x + 250, y + 5);
x = 0;
y += 30;
}
}
Any advice is appreciated.