Un saluto a tutti, chiedo un aiuto per stampare una datagridview..mi spiego...il programma di V.B. è collegato a un db in access dove si trova la mia tabella che visualizzo in una datagridview.
I dati contenuti all'interno della tabella in access sono collegati a altre tabelle nel medesimo db access, il problema è:
-riesco a stampare la datagridview ma non i dati che desidero, perché la dgv visualizza l'ID della tabella è non il valore testuale selezionato e visualizzato.
questo è il codice che uso...funziona bene, vorrei solo cambiare ciò che viene visuazzato, anziché vedere l'id associato a una cella, vedere il suo testo, in più, all'interno della dgv ci sono delle checkbox, non visualizzo la spunta ma visualizzo "true" o "false".
Ho provato ad utilizzare invokepaint come suggerito da Microsoft, ma la dvg viene stampata in alto a sx grande come un francobollo!
Grazie per i consigli
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Dim disegnasfondo As New PaintEventArgs(e.Graphics, New Rectangle(New Point(0, 0), DataGridView1.Size))
'Me.InvokePaint(DataGridView1, disegnasfondo)
' Dim posX As Integer
'Dim posY As Integer = e.MarginBounds.Top
'Dim Rettangolo As Rectangle
'
'Dim Altezza As Integer = DataGridView1.RowTemplate.Height
'Dim NormalFont As Font = New System.Drawing.Font("verdana", 11.25!, FontStyle.Regular)
'Dim BoldFont As Font = New System.Drawing.Font("verdana", 11.25!, FontStyle.Bold)
'Static righeStampate As Integer = 0
'Static pagineStampate As Integer = 0
'Dim righeTotali As Integer = DataGridView1.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
'***INTESTAZIONE DELLA DGV FINO A NEXT
' posX = CType((e.MarginBounds.Width - 360) / 2 + e.MarginBounds.Left, Integer)
posX = CType(e.MarginBounds.Left, Integer)
Dim dimensioneCella As System.Drawing.SizeF
Dim incremento As Integer
For Each colonna As DataGridViewColumn In DataGridView1.Columns
dimensioneCella = e.Graphics.MeasureString(colonna.HeaderText.ToStri ng, 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)
posX = CType(e.MarginBounds.Left, Integer)
If i = righeTotali - 1 Then
e.HasMorePages = False
Exit For
End If
For Each colonna As DataGridViewColumn In DataGridView1.Columns
'testo = DataGridView1.Rows(i).Cells(colonna.Name).Value.To String
testo = DataGridView1.Rows(i).Cells(colonna.Name).Value.To String
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
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.MinMargins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
PageSetupDialog1.PageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
End Sub