Como puedo imprimir fecha sin hora
Publicado por José Vicente (113 intervenciones) el 15/09/2020 12:58:02
Hola tengo un form con un botón de imprimir una BD Access. En el datagrid me muestra el campo fecha bien, osea, sólo la fecha pero cuando imprimo la BD me lo imprime como fecha/hora aunque el campo está declarado como fecha y fecha corta. ¿Qué puedo hacer? Gracias.
Adjunto el código del botón:
Adjunto el código del botón:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'DEFINIMOS LA FUENTE QUE VAMOS A USAR PARA IMPRIMIR
Dim printFont As System.Drawing.Font = New Drawing.Font("Verdana", 10, FontStyle.Regular)
Dim topmargin As Double = e.MarginBounds.Top
Dim yPos As Double = 0
Dim linesPerPage As Double = 0
Dim count As Integer = 0
Dim texto As String = ""
Dim row As System.Windows.Forms.DataGridViewRow
'CALCULAMOS EL NÚMERO DE LÍNEAS QUE CABEN EN CADA PÁGINA
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
'IMPRIMIMOS LAS CABECERAS
Dim header As DataGridViewHeaderCell
For Each column As DataGridViewColumn In DataGridView1.Columns
header = column.HeaderCell
texto += " " & header.FormattedValue.ToString() & " "
Next
yPos = topmargin + (count * printFont.GetHeight(e.Graphics))
e.Graphics.DrawString(texto, printFont, System.Drawing.Brushes.Black, 10, yPos)
'DEJAMOS UNA LÍNEA DE SEPARACIÓN
count += 2
'RECORREMOS EL DATAGRIDVIEW HASTA LLEGAR AL TOPE DE LÍNEAS DE LA PÁGINA O EL FINAL DEL DATAGRIDVIEW
While count < linesPerPage AndAlso i < DataGridView1.Rows.Count
row = DataGridView1.Rows(i)
DataGridView1.Rows(i).Cells(0).Style.Format = "dd/MM/yyyy"
texto = ""
For Each celda As System.Windows.Forms.DataGridViewCell In row.Cells
'COMPROBAMOS QUE LA CELDA NO SEA NULA, SI PERMITIMOS AÑADIR FILAS ESTO ES MUY IMPORTANTE
If celda.Value IsNot Nothing Then
texto += " " & celda.Value.ToString() & " "
End If
Next
'CALCULAMOS LA POSICIÓN EN QUE SE ESCRIBE LA LÍNEA
yPos = topmargin + (count * printFont.GetHeight(e.Graphics))
'ESCRIBIMOS LA LINEA CON EL OBJETO GRAPHICS
e.Graphics.DrawString(texto, printFont, System.Drawing.Brushes.Black, 10, yPos)
'INCREMENTAMOS LOS CONTADORES
count += 1
i += 1
End While
'COMPROBAMOS SI QUEDAN MÁS FILAS POR IMPRIMIR, SI ES ASÍ SALDRÁN EN LA SIGUIENTE PÁGINA
If i < DataGridView1.Rows.Count Then
e.HasMorePages = True
Else
'SI LLEGAMOS AL FINAL DE HASMOREPAGES SE ESTABLECE A FALSE PRA DEJAR DE IMPRIMIR
e.HasMorePages = False
'HAY QUE PONER EL CONTADOR A 0 PARA QUE NO SE QUEDE PILLADA LA VARIABLE i Y NO IMPRIMA NADA
i = 0
End If
End Sub
Valora esta pregunta
0