Как напечатать страницы множественные объекта datagridview
I have a DataGridView with 10 columns. The number of rows could be anywhere from 10 to 700. I would like to be able to print 50 rows on a page (Letter Size portrait).I also want to have the headers at the top of each page. I thought that I could make a bitmap of the headers and another bitmap of the first 50 rows for page one, another bitmap of 50 rows for page two etc. I have not been able to make the bitmaps of the separate areas with the exception of the headers. When I try to make a bitmap of the first 50 rows it always includes the headers and I am unable to create a new bitmap starting with row 51. I am sure there are better techniques to print multiple pages of a datagridview but I thought this was a good one. The reason for making a bitmap is because the rows much higher than 50 are captured even though they are not displayed on the screen. I did not get to the multipage issue yet. I will gratefully accept suggestions.
Существует множество статей и фрагментов кода, обсуждающих эту тему, но ни одна из них не показывает метод решения этой проблемы.
Что я уже пробовал:
Private Sub Pd_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles Pd.PrintPage Dgv1.Height = Dgv1.RowCount * Dgv1.RowTemplate.Height 'Create a Bitmap and draw the DataGridView Headers on it. Dim bitmap0 As Bitmap = New Bitmap(Dgv1.Width, 25) Dgv1.DrawToBitmap(bitmap0, New Rectangle(0, 0, Dgv1.Width, 25)) 'Create a second bitmap and draw the DataGridView with up to 700 pixels (approx 30 Rows) High Without the header row Dim bitmap1 As Bitmap = New Bitmap(Dgv1.Width, 700) Dgv1.DrawToBitmap(bitmap1, New Rectangle(0, 25, Dgv1.Width, 700)) e.Graphics.DrawImage(bitmap0, 0, 100, Dgv1.Width, 25) e.Graphics.DrawImage(bitmap1, 0, 125, Dgv1.Width, 700) End Sub