salve a tutti avrei necesssità di stampare il contenuto di un datagridview su carta.
Per stampare riesco a stamparlo usando la classe printdocument, ma il problema si pone quando il datagridview ha molti record e quidni è richiesta la stampa su più pagine. Ho provato a usare e.hasmorepages per farlo stampare su più pagine, ma le pagine che mi escono dalla stampante sono tutte uguali.
Vi posto l'abbozzo di codice che ho scritto:
codice:
 Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim cont As Integer, I As Integer
        Static righe As Integer
        Dim hRow As Integer = 25
        Dim left As Integer
        Dim top As Integer = 20

        e.Graphics.DrawString("ID", Data.Font, Brushes.Black, left + 49, top)
        e.Graphics.DrawString("Data", Data.Font, Brushes.Black, left + 92, top)
        e.Graphics.DrawString("Scheda", Data.Font, Brushes.Black, left + 242, top)
        e.Graphics.DrawString("Descrizione", Data.Font, Brushes.Black, left + 335, top)
        Do
            For Each dgr As DataGridViewRow In Data.Rows
                cont = 0
                top += hRow
                left = 50
                For Each dgc As DataGridViewCell In dgr.Cells
                    e.Graphics.DrawString(dgc.Value, Data.Font, Brushes.Black, left, top)
                    Select Case cont
                        Case 0 : left += 45
                        Case 2 : left += 90
                        Case Else : left += 150
                    End Select
                    cont += 1
                Next
            Next
            righe += 45
            e.HasMorePages = True
            If righe > Data.Rows.Count Then e.HasMorePages = False : Exit Do
        Loop Until righe < Data.Rows.Count
    End Sub
ciao a tutti
luca