We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Printing from a datagrid

Last post 05-08-2008 1:08 PM by AllenSmith. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-06-2008 2:53 PM

    • Jessicar
    • Not Ranked
    • Joined on 04-24-2008
    • United Kingdom
    • New Member
    • Points 40

    Printing from a datagrid

    Im trying to print from a data grid but all I get when I ask to preview or print the data is "System.Data.DataRowView" printed out once for each of the items in the data grid. This is the code I have used but I can't figure out how to make it print the contents:

        Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
            'define the number of copies to print
            AllGuestsPrint.PrinterSettings.Copies = 1
            'send the print event which will be picked up by 'Reciept_PrintPage below
            'This links Button2 to a particular PrintDocument object you would have dragged onto your form.
            AllGuestsPrint.Print()

        End Sub
        Private Sub AllGuestsPrint_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles AllGuestsPrint.PrintPage
            'User has clicked on the print button, so setup the string you want to print

            'define variables
            Dim iText As Integer
            Dim AllGuests As String

            'initialise output text
            AllGuests = ""

            For iText = 0 To DataGridView1.DataSource.Count - 1
                AllGuests = AllGuests + (DataGridView1.DataSource(iText).ToString())
                AllGuests = AllGuests + vbCrLf
            Next

            'Just for debug purposes, output the receipt variable so you know what will be printed
            MsgBox("The Following will be Printed:-" + vbCrLf + vbCrLf + AllGuests)
            'print the string
            e.Graphics.DrawString(AllGuests, DataGridView1.Font, Brushes.Black, 100, 100)
        End Sub

     

    Please help?

    xxx

    • Post Points: 10
  • 05-08-2008 1:08 PM In reply to

    • AllenSmith
    • Not Ranked
    • Joined on 04-08-2008
    • India
    • Junior Member
    • Points 135

    Re: Printing from a datagrid

     

    Hello,

    You may try the solution in the given links.

    http://www.codeproject.com/KB/printing/DataGrid_Printing_Class.aspx

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=55331&SiteID=1

    Hope this will help.

    Regards,

    Allen Smith
    ComponentOne LLC,

    www.componentone.com

     

    • Post Points: 5
Page 1 of 1 (2 items)