tombhunter
New Member
- Joined
- Mar 29, 2009
- Messages
- 1
Hi, I am trying to print the items which I have entered into a Listview box. At the moment all the data entered appears in the text box and all the calculations are completed successfully. However when i try to print the data in the listview it comes up with the title and the date just as I want it, but then underneath the title where the numbers and collum headers should be it just has:
System.Windows.Forms.ListView+ListViewItemCollection
It has this listed one under the other 6 times, it then stops and has a gap before listing,
Monthly Cost: 0
Monthly Cost Over a Year: 6
Monthly Cost over 2 Years : 6
I believe that the problem is around the line just after the beginning of the loop where it says, "SingleMonthlyCost = lstExpenses.Items.ToString()"
The code for my whole printing function is as follows, this consists of a module as well:
System.Windows.Forms.ListView+ListViewItemCollection
It has this listed one under the other 6 times, it then stops and has a gap before listing,
Monthly Cost: 0
Monthly Cost Over a Year: 6
Monthly Cost over 2 Years : 6
I believe that the problem is around the line just after the beginning of the loop where it says, "SingleMonthlyCost = lstExpenses.Items.ToString()"
The code for my whole printing function is as follows, this consists of a module as well:
Code:
<TABLE style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; MARGIN: 2px 0px; WIDTH: 99%; BORDER-BOTTOM: #eee 0px solid; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #fff; BORDER-RIGHT-WIDTH: 0px" cellSpacing=0 cellPadding=0><TBODY><TR><TD>Private PrintPageSettings As New PageSetupDialog </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Private StringtoPrint As String </TD></TR><TR><TD> Private PrintFont As New Font("Courier New", 12) </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Dim Print As System.Array </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click </TD></TR><TR><TD> If [COLOR=red]PrintDialog1.ShowDialog[/COLOR] = [COLOR=blue]Windows[/COLOR].Forms.DialogResult.OK Then </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> PrintDocument1.Print() </TD></TR><TR><TD> End If </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> End Sub </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Private Sub PrintDocument1_PrintPage(ByVal Sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage </TD></TR><TR><TD> Static MonthlyCost, MonthlyCostYear, MonthlyCostTwoYears As Short </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Static ExpensesPrinted As Short </TD></TR><TR><TD> Dim LinesPrinted As Short </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Dim LinesRequired As Short </TD></TR><TR><TD> Dim FontHeight As Short </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Dim Titles, SingleMonthlyCost As String </TD></TR><TR><TD> Dim MyFont As New Font("Courier New", 12, FontStyle.Bold) </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Dim MyTitleFont As New Font("Courier New", 14, FontStyle.Bold) </TD></TR><TR><TD> Dim X, Y As Short </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Dim FooterPrinted As Boolean </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]FontHeight[/COLOR] = [COLOR=blue]MyFont[/COLOR].GetHeight(e.Graphics) </TD></TR><TR><TD> [COLOR=red]LinesRequired[/COLOR] = e.MarginBounds.Height / FontHeight </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]X[/COLOR] = [COLOR=blue]50[/COLOR] </TD></TR><TR><TD> [COLOR=red]Y[/COLOR] = [COLOR=blue]50[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> e.Graphics.DrawString("List of Current Prospect Customers Expenses " & Format(Today, "long date"), MyTitleFont, Brushes.Black, X, Y) </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]LinesPrinted[/COLOR] = [COLOR=blue]2[/COLOR] </TD></TR><TR><TD> [COLOR=red]Y[/COLOR][COLOR=blue]Y[/COLOR] = Y + FontHeight * 2 </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Do While (LinesPrinted [COLOR=blue]<[/COLOR] [COLOR=black][B]LinesRequired[/B][/COLOR]) And (ExpensesPrinted [COLOR=blue]<[/COLOR]= lstExpenses.Items.Count - 1) </TD></TR><TR><TD> [COLOR=red]SingleMonthlyCost[/COLOR] = [COLOR=blue]lstExpenses[/COLOR].Items.ToString() </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> e.Graphics.DrawString(SingleMonthlyCost, Font, Brushes.Black, X, Y) </TD></TR><TR><TD> [COLOR=red]LinesPrinted[/COLOR][COLOR=blue]LinesPrinted[/COLOR] = LinesPrinted + 1 </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]ExpensesPrinted[/COLOR][COLOR=blue]ExpensesPrinted[/COLOR] = ExpensesPrinted + 1 </TD></TR><TR><TD> If SingleMonthlyCost.IndexOf("Monthly Cost") [COLOR=blue]<[/COLOR]> -1 Then </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]MonthlyCost[/COLOR][COLOR=blue]MonthlyCost[/COLOR] = MonthlyCost + 1 </TD></TR><TR><TD> Else </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]MonthlyCostYear[/COLOR][COLOR=blue]MonthlyCostYear[/COLOR] = MonthlyCostYear + 1 </TD></TR><TR><TD> [COLOR=red]MonthlyCostTwoYears[/COLOR][COLOR=blue]MonthlyCostTwoYears[/COLOR] = MonthlyCostTwoYears + 1 </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> End If </TD></TR><TR><TD> [COLOR=red]Y[/COLOR][COLOR=blue]Y[/COLOR] = Y + FontHeight </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Loop </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> If [COLOR=red]ExpensesPrinted[/COLOR] = [COLOR=blue]lstExpenses[/COLOR].Items.Count Then </TD></TR><TR><TD> Call PrintBlankLine(X, Y, FontHeight, Font, e) </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> e.Graphics.DrawString("Monthly Cost: " & MonthlyCost, Font, Brushes.Black, X, Y) </TD></TR><TR><TD> [COLOR=red]Y[/COLOR][COLOR=blue]Y[/COLOR] = Y + FontHeight </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> e.Graphics.DrawString("Monthly Cost Over a Year: " & MonthlyCostYear, Font, Brushes.Black, X, Y) </TD></TR><TR><TD> [COLOR=red]Y[/COLOR][COLOR=blue]Y[/COLOR] = Y + FontHeight </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> e.Graphics.DrawString("Monthly Cost Over 2 Years: " & MonthlyCostTwoYears, Font, Brushes.Black, X, Y) </TD></TR><TR><TD> [COLOR=red]FooterPrinted[/COLOR] = [COLOR=blue]True[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> End If </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> If (LinesPrinted [COLOR=blue]<[/COLOR] [COLOR=black][B]LinesRequired[/B][/COLOR]) Or (FooterPrinted) Then </TD></TR><TR><TD> [COLOR=red]e.HasMorePages[/COLOR] = [COLOR=blue]False[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]ExpensesPrinted[/COLOR] = [COLOR=blue]0[/COLOR] </TD></TR><TR><TD> [COLOR=red]MonthlyCost[/COLOR] = [COLOR=blue]0[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]MonthlyCostYear[/COLOR] = [COLOR=blue]0[/COLOR] </TD></TR><TR><TD> [COLOR=red]MonthlyCostTwoYears[/COLOR] = [COLOR=blue]0[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Else </TD></TR><TR><TD> [COLOR=red]e.HasMorePages[/COLOR] = [COLOR=blue]True[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> End If </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> End Sub </TD></TR><TR><TD> </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click </TD></TR><TR><TD> [COLOR=red]PrintPreviewDialog1.Document[/COLOR] = [COLOR=blue]PrintDocument1[/COLOR] </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> PrintPreviewDialog1.ShowDialog() </TD></TR><TR><TD> End Sub </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> </TD></TR><TR><TD>Module: </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> </TD></TR><TR><TD>Public Sub PrintBlankLine(ByVal XCoord As Short, ByRef YCoord As Short, ByVal OneLineHeight As Short, ByVal FontToUse As Font, ByVal e As System.Drawing.Printing.PrintPageEventArgs) </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]YCoord[/COLOR][COLOR=blue]YCoord[/COLOR] = YCoord + OneLineHeight </TD></TR><TR><TD> e.Graphics.DrawString("", FontToUse, Brushes.Black, XCoord, YCoord) </TD></TR><TR><TD style="BACKGROUND-COLOR: #f7f7f7"> [COLOR=red]YCoord[/COLOR][COLOR=blue]YCoord[/COLOR] = YCoord + OneLineHeight </TD></TR><TR><TD> End Sub </TD></TR></TBODY></TABLE>