Printing a DataGrid

databases United States
  • 19 years ago

    Does anyone know how to print a DataGrid in VB.  I have a DataGrid that displays on the screen.  I need the ability to have the user click on a button and have the grid sent to a printer.  I am displaying about 200 different Grids within the application, so I really don't want to use diverse coding for each grid.


    Any help would be appreciated.  You can email me at [email protected]

  • 19 years ago

    You BitBlt from the grid to the Printer object.  I made up the scale 1...8000 because I don't know the size (in twips) of the grid.
    Your program knows that. You will also have to position the output on the printer. with x and y.


    to change the size of the printed object use StrecthBlt api, which does BitBlt plus a re-size of the image.


    Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long


    Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


    Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source


    Dim GridDC as long
    GridDC = GetDC(MyDatagrid1.hwnd)
    ' bitblt data to printer.hDC


    Call BitBlt(Printer.hDC,1,1,8000,12000,GridDC,1,1,SRCCOPY)
    Printer.EndDoc


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard