I am trying to get the contests of a list box to print. I have 4 colums in the list box with data underneath. here is my code.
But im am getting an error on:
InvalidCastException was unhandled. Conversion from Type 'ListViewItem' to type 'String' is not valid
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim t As Integer = -1
Dim ListBoxItem As String = String.Empty
For Each LBItem As String In StoreList.Items
If t >= 0 Then
ListBoxItem = ListBoxItem & vbCrLf & LBItem
Else
t = t + 1
End If
Next
Static Lines() As String = ListBoxItem.Split(vbCrLf)
Static Font As New Font("Arial", 16, FontStyle.Regular, GraphicsUnit.Pixel)
Static I As Integer
Dim VerticalPos As Integer = 20
Do
e.Graphics.DrawString(Lines(I), Font, Brushes.Black, 20, VerticalPos)
I += 1
VerticalPos += Font.Height
If VerticalPos > e.PageBounds.Bottom Then
e.HasMorePages = True
Return
End If
Loop Until I = Lines.Length
End SubCode:
LBItem As String In StoreList.ItemsQuote:
InvalidCastException was unhandled. Conversion from Type 'ListViewItem' to type 'String' is not valid