Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

Printing a List Box

$
0
0
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.
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 Sub

But im am getting an error on:
Code:

LBItem As String In StoreList.Items
Quote:

InvalidCastException was unhandled. Conversion from Type 'ListViewItem' to type 'String' is not valid

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>