 |
| Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 14th, 2012, 11:43 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
VB.Net 2008 Save Print Preview DataGridView inside txt file or Excel
[FONT='Tahoma','sans-serif']Iâm using VB.Net 2008 application program.[/FONT]
[FONT='Tahoma','sans-serif']Iâm using DataGridView. I have a Print Preview option where i need to print the DataGridView. [/FONT]
[FONT='Tahoma','sans-serif']
Quote:
[FONT='Tahoma','sans-serif']Using "DataGridView1.Rows.Add" iâm adding rows to datagridview.[/FONT]
[FONT='Tahoma','sans-serif']
|
[/FONT]
[FONT='Tahoma','sans-serif']Iâm using this code for Print Preview.[/FONT]
[FONT='Tahoma','sans-serif']
Code:
[FONT='Tahoma','sans-serif']Dim MyDataGridViewPrinter As DataGridViewPrinter[/FONT]
[FONT='Tahoma','sans-serif'] Private Function SetupThePrinting() As Boolean[/FONT]
[FONT='Tahoma','sans-serif'] Dim MyPrintDialog As PrintDialog = New PrintDialog()[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.AllowCurrentPage = False[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.AllowPrintToFile = False[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.AllowSelection = False[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.AllowSomePages = True[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.PrintToFile = False[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.ShowHelp = False[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintDialog.ShowNetwork = False[/FONT]
[FONT='Tahoma','sans-serif'] PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings[/FONT]
[FONT='Tahoma','sans-serif'] PrintDocument1.DefaultPageSettings.Margins = New Margins(10, 10, 10, 10)[/FONT]
[FONT='Tahoma','sans-serif'] MyDataGridViewPrinter = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, "Manager", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)[/FONT]
[FONT='Tahoma','sans-serif'] Return True[/FONT]
[FONT='Tahoma','sans-serif'] End Function[/FONT]
[FONT='Tahoma','sans-serif'] Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage[/FONT]
[FONT='Tahoma','sans-serif'] Dim more As Boolean[/FONT]
[FONT='Tahoma','sans-serif'] more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)[/FONT]
[FONT='Tahoma','sans-serif'] If more Then e.HasMorePages = True[/FONT]
[FONT='Tahoma','sans-serif'] End Sub[/FONT]
[FONT='Tahoma','sans-serif'] ' The Print Preview Button[/FONT]
[FONT='Tahoma','sans-serif'] Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click[/FONT]
[FONT='Tahoma','sans-serif'] If SetupThePrinting() Then[/FONT]
[FONT='Tahoma','sans-serif'] Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintPreviewDialog.Document = PrintDocument1[/FONT]
[FONT='Tahoma','sans-serif'] MyPrintPreviewDialog.ShowDialog()[/FONT]
[FONT='Tahoma','sans-serif'] End If[/FONT]
[FONT='Tahoma','sans-serif'] End Sub[/FONT]
[FONT='Tahoma','sans-serif']
[/FONT]
[FONT='Tahoma','sans-serif']I searched a lot, but I couldnât find it.[/FONT]
[FONT='Tahoma','sans-serif']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.[/FONT]
[FONT='Tahoma','sans-serif']Thanks in advance.[/FONT]
|
|
 |