Results 1 to 3 of 3

Thread: Save Print Preview DataGridView inside txt file or Excel

  1. #1
    remya1000 is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Mar 2007
    Posts
    122
    Reputation
    80

    Save Print Preview DataGridView inside txt file or Excel

    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.

    Code:
    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.

  2. #2
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    309
    Quote Originally Posted by remya1000 View Post
    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"?

  3. #3
    remya1000 is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Mar 2007
    Posts
    122
    Reputation
    80
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking