Hi All,
How can I send the contents of a Datagrid to a printer on LPT1 with the table names in order and the rows and columns tabulated correctly.
Cheers
R
Printable View
Hi All,
How can I send the contents of a Datagrid to a printer on LPT1 with the table names in order and the rows and columns tabulated correctly.
Cheers
R
Hi
Printing is the most annoying part of Windows programming. You can use a 3rd party control or u can code it. Here is some sample code for a FlexGrid... am sure u can adjust for DataGrid.
Regards
Stuart
VB Code:
'Print Grid for any page Sub priPrintGrid() Dim lintPageNum As Integer Dim lintGridWidth As Integer Dim lintScaleLeft As Integer Dim lintScaleWidth As Integer Dim llngRows As Long Dim llngCols As Long Dim lstrText As String Dim lintLeftPosn As Integer Dim lintColWidth As Integer Dim lintColAlign As Integer Dim lintTextWidth As Integer Dim lintPrintSpace As Integer On Error Resume Next lintPageNum = 1 lintGridWidth = Grid1.Width lintScaleLeft = Printer.ScaleLeft lintScaleWidth = Printer.ScaleWidth 'Print Grid rows With Grid1 For llngRows = 0 To .Rows -1 For llngCols = 0 To .Cols - 1 lstrText = Trim$(.TextMatrix(llngRows, llngCols)) lintTextWidth = Printer.TextWidth(lstrText) lintLeftPosn = .ColPos(llngCols) / lintGridWidth * lintScaleWidth lintColWidth = .ColWidth(llngCols) / lintGridWidth * lintScaleWidth lintColAlign = .ColAlignment(llngCols) 'Print cell priPrintCell lstrText, lintTextWidth, lintLeftPosn, lintColWidth, lintColAlign Next Printer.Print " " 'Test for new page With Printer lintPrintSpace = .ScaleHeight - .ScaleTop - .CurrentY End With If lintPrintSpace < 3 * Printer.TextHeight("A") Then lintPageNum = lintPageNum + 1 If lintPageNum \ 5 = lintPageNum / 5 Then Printer.EndDoc End If Next End With End Sub 'Print grid cells Sub priPrintCell(lstrText As String, lintTextWidth As Integer, _ lintLeftPosn As Integer, lintColWidth As Integer, _ lintColAlign As Integer) Dim lintMaxText As Integer On Error Resume Next If lintColAlign = flexAlignLeftCenter Then 'Grid / total Printer.CurrentX = lintLeftPosn + 80 'Left align Else Printer.CurrentX = lintLeftPosn + (lintColWidth - lintTextWidth) 'Right align End If 'In case text is wider than column If lintColWidth > 0 And lintColWidth < lintTextWidth Then 'Reduce column width lintMaxText = Round(lintColWidth / lintTextWidth * Len(lstrText), 0) - 1 lstrText = Left$(lstrText, lintMaxText) End If If lintColWidth > 0 Then Printer.Print lstrText; End Sub
This is basic and u can add stuff to print lines, bolding etc etc... also i have cut and pasted stuff here and removed bits and pieces so if u get an error pls let me know specific type and i will fix
Is there something very very very simple and alot smaller to use that
will work with alot of columns?