Scusate per il crossing posting ma non ho trovato niente di utile in masterdrive:

Ciao a tutti,

quando cerco di stampare una pagina non mi stampa l'ultima riga, ecco il mio codice:

codice:
        Dim posX As Integer

        Dim posY As Integer = e.MarginBounds.Top

        Dim Rettangolo As Rectangle

        Dim Altezza As Integer = francesco.RowTemplate.Height

        Dim NormalFont As Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, FontStyle.Regular)

        Dim BoldFont As Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, FontStyle.Bold)

        Static righeStampate As Integer = 0

        Static pagineStampate As Integer = 0

        Dim righeTotali As Integer = francesco.Rows.Count

        Dim righePerPagina As Integer = CType(e.MarginBounds.Height / Altezza, Integer)

        Dim nPagine As Integer

        If righeTotali Mod righePerPagina > 0 Then

            nPagine = (righeTotali \ righePerPagina) + 1

        Else

            nPagine = (righeTotali \ righePerPagina)

        End If

        posX = CType((e.MarginBounds.Width - 360) / 2 + e.MarginBounds.Left, Integer)

        Dim dimensioneCella As System.Drawing.SizeF

        Dim incremento As Integer

        For Each colonna As DataGridViewColumn In francesco.Columns

            dimensioneCella = e.Graphics.MeasureString(colonna.HeaderText.ToString, NormalFont)
            incremento = CType((colonna.Width - dimensioneCella.Width) / 2, Integer)

            Rettangolo = New Rectangle(posX, posY, colonna.Width, Altezza)

            e.Graphics.DrawRectangle(Pens.Black, Rettangolo)

            e.Graphics.DrawString(colonna.HeaderText, BoldFont, Brushes.Black, posX + incremento, posY + 5)
            posX += colonna.Width

        Next

        posY += Altezza

        Dim testo As String

        For i As Integer = righeStampate To righeStampate + righePerPagina - 2

            posX = CType((e.MarginBounds.Width - 360) / 2 + e.MarginBounds.Left, Integer)

            If i = righeTotali - 1 Then

                e.HasMorePages = False
                Exit For

            End If

            For Each colonna As DataGridViewColumn In francesco.Columns
                If francesco.Rows(i).Cells(colonna.Name).Value Is Nothing Then
                    testo = " "
                Else
                    testo = francesco.Rows(i).Cells(colonna.Name).Value.ToString
                End If
                dimensioneCella = e.Graphics.MeasureString(testo.ToString, NormalFont)
                incremento = CType((colonna.Width - dimensioneCella.Width) / 2, Integer)
                Rettangolo = New Rectangle(posX, posY, colonna.Width, Altezza)

                e.Graphics.DrawRectangle(Pens.Black, Rettangolo)

                e.Graphics.DrawString(testo, NormalFont, Brushes.Black, posX + incremento, posY + 5)
                posX += colonna.Width

            Next

            righeStampate += 1
            posY += Altezza

        Next

        pagineStampate += 1

        If pagineStampate < nPagine Then

            e.HasMorePages = True
            posY = e.MarginBounds.Top

        Else

            e.HasMorePages = False
            righeStampate = 0
            pagineStampate = 0

        End If
Datagridview da applicazione: https://ibb.co/n1sJydv

Pre-view della stampa: https://ibb.co/dfy1sCp