C# Windows Form, Print multiple pages from checked item on dataGridView row in custom label form. Help.

  • Thread starter Thread starter DuriDuri
  • Start date Start date
D

DuriDuri

Guest
I am making a label print but I am stuck. This is the requirement of this label print program.


1. Import table from excel sheet and display on datagridview. Checked!

2. Get values from checked row and populate them on custom label format. Checked!

3. Print 1 label per page on all selected value. - I am Stuck here!


As you can see code I wrote below, I have no problem printing single label if I only select one row but if I select multiple row, it just tries to display everything in one page. I have set custom page size as height 100, width 200 which is one label size I am using. So how do I make this work so it jumps to next page when I select multiple value? If I use e.HasMorePage = true; anywhere on my code, it gets caught in foreach loop causing error. If I use break; it just breaks after printing first select value. Help Please.



private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

int height = 0;

foreach (var row in dataGridView1.Rows)
{
DataGridViewRow checkedRow = row as DataGridViewRow;
if ((bool?)checkedRow.Cells[0].Value == true)
{
string barCode = checkedRow.Cells[2].Value.ToString();
Zen.Barcode.Code128BarcodeDraw brCode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
PictureBox pic = new PictureBox();
pic.Image = brCode.Draw(barCode, 40);
Image img = pic.Image;
height += 10;
e.Graphics.DrawString(checkedRow.Cells[3].FormattedValue.ToString(), new Font("Arial", 8, FontStyle.Italic | FontStyle.Bold), Brushes.Black, new Point(10, height));
height += 15;
e.Graphics.DrawString(checkedRow.Cells[4].FormattedValue.ToString(), new Font("Arial", 8, FontStyle.Bold), Brushes.Black, new Point(10, height));
height += 20;
e.Graphics.DrawImage(img, new Rectangle(12, height, 100, 15));
height += 15;
e.Graphics.DrawString(checkedRow.Cells[2].FormattedValue.ToString(), new Font("Arial", 6, FontStyle.Bold), Brushes.Black, new Point(10, height));
height += 30;
}
}
}

Continue reading...
 
Back
Top