Save Print Preview DataGridView inside txt file or Excel

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
I’m using VB.Net 2008 application program.

I’m using DataGridView. I have a Print Preview option where i need to print the DataGridView.

Using "DataGridView1.Rows.Add" i’m adding rows to datagridview.

I’m using this code for Print Preview.

VB.NET:
Dim MyDataGridViewPrinter As DataGridViewPrinter


    Private Function SetupThePrinting() As Boolean
        Dim MyPrintDialog As PrintDialog = New PrintDialog()

        MyPrintDialog.AllowCurrentPage = False
        MyPrintDialog.AllowPrintToFile = False
        MyPrintDialog.AllowSelection = False
        MyPrintDialog.AllowSomePages = True
        MyPrintDialog.PrintToFile = False
        MyPrintDialog.ShowHelp = False
        MyPrintDialog.ShowNetwork = False

        PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings
        PrintDocument1.DefaultPageSettings.Margins = New Margins(10, 10, 10, 10)

        MyDataGridViewPrinter = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, "Manager", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
        
        Return True
    End Function

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim more As Boolean

        more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
        If more Then e.HasMorePages = True
    End Sub


    ' The Print Preview Button
    Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
        If SetupThePrinting() Then
            Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
            MyPrintPreviewDialog.Document = PrintDocument1
            MyPrintPreviewDialog.ShowDialog()
        End If
    End Sub

I searched a lot, but I couldn’t find it.

If you know how i can Save Print Preview inside text file or Excel, please help me. If you can provide an example, that will be so helpful.

Thanks in advance.
 
If you know how i can Save Print Preview inside text file or Excel, please help me.

Could you elaborate a little about what you want here; I can't understand the sentence as worded. Do you want to save the print preview or do you want to print? What do you mean by "inside text file or Excel"?
 
Thanks Paszt for your reply.

i want to Save the print preview.

If you know how to save the print preview, please help me.

Thanks in Advance.
 
Back
Top