Hi i have problem on printing output on vb.net, I run-out of ideas in my mind. I hope you can help me. Here's my code:
If ComboBox1.Text = "Sampled" Then
For i As Integer = 0 To DataGridView1.RowCount - 1
If DataGridView1.Item(0, i).Value = "True" Then
Dim ContainerNo = DataGridView1.Item(18, i).Value
Dim TotalContainer = DataGridView1.Item(19, i).Value
'e.Graphics.DrawImage(image:=myBitmap2, point:=New Point(110, 40))
e.Graphics.DrawString("SAMPLED", font3, Brushes.Black, 120, 70)
e.Graphics.DrawString("CONTAINER No:________________OF________________", font1, Brushes.Black, 90, 140)
e.Graphics.DrawString("REMARKS:_______________________________________", font1, Brushes.Black, 90, 160)
e.Graphics.DrawString("SAMPLED BY:", font1, Brushes.Black, 170, 220)
e.Graphics.DrawString("____________________", font1, Brushes.Black, 155, 235)
e.Graphics.DrawString("QC SAMPLER/DATE", font1, Brushes.Black, 160, 250)
e.Graphics.DrawString(ContainerNo, font1, Brushes.Black, 190, 138)
e.Graphics.DrawString(TotalContainer, font1, Brushes.Black, 280, 138)
e.Graphics.DrawString(TextBox12.Text, font1, Brushes.Black, 160, 158)
' e.HasMorePages = True
index = 1
If index <= x Then
e.HasMorePages = True
MessageBox.Show("True")
Else
e.HasMorePages = False
MessageBox.Show("false")
End If
End If
Next
here's my current output now
I want my output to be like this
1st page: 2 of 3 (2 is based from Dim ContainerNo = DataGridView1.Item(18, i).Value) and (3 is from Dim TotalContainer = DataGridView1.Item(19, i).Value)
2nd page: 3 of 3
Sadly my current output now is containerNo:2 and containerNo:3 are overlapping each other on both pages, I hope you can help me
CodePudding user response:
Remove the loop. This function can be called multiple times in a single print job (HasMorePages
controls whether it will be called again). Each time it's called you only print one page worth of data.
Dim i As Integer = index
If ComboBox1.Text = "Sampled" AndAlso DataGridView1.Item(0, i).Value = "True" Then
Dim ContainerNo = DataGridView1.Item(18, i).Value
Dim TotalContainer = DataGridView1.Item(19, i).Value
e.Graphics.DrawString("SAMPLED", font3, Brushes.Black, 120, 70)
e.Graphics.DrawString("CONTAINER No:________________OF________________", font1, Brushes.Black, 90, 140)
e.Graphics.DrawString("REMARKS:_______________________________________", font1, Brushes.Black, 90, 160)
e.Graphics.DrawString("SAMPLED BY:", font1, Brushes.Black, 170, 220)
e.Graphics.DrawString("____________________", font1, Brushes.Black, 155, 235)
e.Graphics.DrawString("QC SAMPLER/DATE", font1, Brushes.Black, 160, 250)
e.Graphics.DrawString(ContainerNo, font1, Brushes.Black, 190, 138)
e.Graphics.DrawString(TotalContainer, font1, Brushes.Black, 280, 138)
e.Graphics.DrawString(TextBox12.Text, font1, Brushes.Black, 160, 158)
End If
'Make sure index is declared OUTSIDE THE METHOD
index = 1
e.HasMorePages = index <= DataGridView1.RowCount - 1