Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 31st, 2012, 05:01 PM
Authorized User
Points: 386, Level: 6
Points: 386, Level: 6 Points: 386, Level: 6 Points: 386, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: windsor, toronto, Canada.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width)

I’m using VB.Net 2008 application program.
I’m using DataGridView. I have a Print option where i need to print the DataGridView.
I’m using this code for Printing and 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, "Price 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

        Try
            more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
            If more Then e.HasMorePages = True
        Catch Ex As Exception
        End Try
    End Sub

    ' The Print Preview Button
    Private Sub btnPrintPreview_Click(ByVal sender As 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

    ' The Print Button
    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        If SetupThePrinting() Then PrintDocument1.Print()
    End Sub

Attached the class i'm using for print.
I have 10 fields showing in datagridview. As the last 5 columns header is long, the datagridview is not fitting inside 1 page (not showing all 10 fields in one single page). But is there a way i can "Text Wrap" the top header column and lock in the width, then it should print across one page perfectly.
I searched a lot, but I couldn’t find it.
If you know how i can "Text Wrap" the top header column and lock in the width to print across one page, please help me. If you can provide an example, that will be so helpful.
Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old February 14th, 2012, 12:56 AM
Authorized User
Points: 386, Level: 6
Points: 386, Level: 6 Points: 386, Level: 6 Points: 386, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: windsor, toronto, Canada.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there a way i can print this in Landscape format, so entire columns will be fit in one page?

this is the code used in class for checking Landscape. but when i try both, it shows same page format.
Code:
 'Claculating the PageWidth and the PageHeight.
        If Not ThePrintDocument.DefaultPageSettings.Landscape Then
            PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Width
            PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Height
        Else
            PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width
            PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Height
        End If

Is it possible? If you know how to print this in Landscape format, please help me. if you can provide an example, that will be so helpful.
Thanks in advance.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing DataGridView in VB 2008 bex WinForms/Console Application Design 5 February 10th, 2012 05:32 PM
Word wrap for column header - Jasper Report ShamPhadtale J2EE 0 September 2nd, 2011 03:25 AM
Printing DataGridView in VB 2008 bex ASP.NET 3.5 Basics 1 June 30th, 2009 02:57 PM
Runtime Column Header Text vinod_yadav1919 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 November 29th, 2008 01:53 AM
How to wrap text in a winform Datagrid (vb.net) cliffd64 VB.NET 2002/2003 Basics 1 September 26th, 2006 03:10 PM



All times are GMT -4. The time now is 01:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.