Listview afdrukken

Status
Niet open voor verdere reacties.

geertd

Gebruiker
Lid geworden
16 nov 2008
Berichten
340
Hallo allemaal,

Weet er iemand hoe ik een listview met collums kan afdrukken?

Alvast bedankt,

Geert
 
Listvieuw

Geertd
Je kan niet rechtstreeks een listvieuw afdrukken.

Je zal in een lus alle regels apart moeten printen op de juiste plaats.

Mrlittle
 
Hoe kan ik dat dan doen?

Ik heb namelijk nog helemaal geen ervaring met het schrijven van printopdrachten.
 
Het is mij gelukt met deze code die Dummy1912 mij had ge-e-maild:

Code:
#Region " Printen"
    'Direct printen Printen
    Public Sub PrintBIll()
        Dim Prev As New PrintPreviewDlg
        With Prev
            .Document = PrintDocument1
            .Document.DefaultPageSettings.Landscape = True
            Ratio = 1
            CurrRow = 0
            .Show()
        End With
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim c As ColumnHeader
        Dim g As Graphics = e.Graphics
        Dim l As Integer = 0
        Dim iCount As Integer
        Dim f As Font = LstView.Font
        Dim b As Brush = Brushes.Black
        Dim currentY As Integer = 0
        Dim maxY As Integer = 0
        Dim gap As Integer = 1
        Dim lvsi As ListViewItem.ListViewSubItem
        Dim colLefts(LstView.Columns.Count) As Integer
        Dim colWidths(LstView.Columns.Count) As Integer
        Dim idx As Integer = 0
        Dim ii As Integer
        Dim lr As RectangleF
        e.HasMorePages = False


        'Title    
        Dim headfont, headfont2 As Font
        Dim X1 As Integer
        Dim Y As Integer
        ' headfont = New Font("Courier New", 16, FontStyle.Bold)
        headfont = New Font(FntFC2.Families(0), 22, FontStyle.Bold, GraphicsUnit.Point)
        headfont2 = New Font("Courier New", 10, FontStyle.Bold)
        X1 = PrintDocument1.DefaultPageSettings.Margins.Left

        
        e.Graphics.DrawString("TITEL - " & Date.Today.Year, headfont, Brushes.DarkRed, X1 + 250, Y + 40)
        With PrintDocument1.DefaultPageSettings

            e.Graphics.DrawLine(Pens.Black, 0, Y + 70, e.PageBounds.Width, Y + 70)
        End With

        'Headings    
        currentY = 100
        For Each c In LstView.Columns
            maxY = Math.Max(maxY, g.MeasureString(c.Text, f, c.Width).Height)
            colLefts(idx) = l
            colWidths(idx) = c.Width
            lr = New RectangleF(colLefts(idx), currentY, colWidths(idx), maxY)
            ' g.DrawString(c.Text, f, b, lr) ' print all columns including hidden columns 

            If lr.Width > 0 Then g.DrawString(c.Text, f, b, lr)
            l += c.Width
            idx += 1
        Next
        currentY += maxY + gap
        g.DrawLine(Pens.Black, 0, currentY, e.PageBounds.Width, currentY)
        currentY += gap
        'Rows    
        iCount = LstView.Items.Count - 1
        For ii = CurrRow To iCount
            If (currentY + maxY + maxY) > e.PageBounds.Height Then
                CurrRow = ii - 1
                e.HasMorePages = True

                currentY += maxY + gap
                Exit For

            End If

            l = 0
            maxY = 0
            idx = 0
            For Each lvsi In LstView.Items(ii).SubItems
                maxY = Math.Max(maxY, g.MeasureString(lvsi.Text, f, colWidths(idx)).Height)
                lr = New RectangleF(colLefts(idx), currentY, colWidths(idx), maxY)
                If lr.Width > 0 Then g.DrawString(lvsi.Text, f, b, lr)
                idx += 1
            Next
            currentY += maxY + gap
        Next
        If (currentY + 60) < e.PageBounds.Height Then
            If Amount < 0 Then
            Else
            End If

            e.HasMorePages = False
        Else

            CurrRow = ii
            e.HasMorePages = True
        End If
    End Sub

#End Region
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan