Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width)
Old 01-31-2012, 04:13 PM VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width)
Experienced Talker

Posts: 39
Name: remya
Trades: 0
I知 using VB.Net 2008 application program.

I知 using DataGridView. I have a Print option where i need to print the DataGridView.

I知 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稚 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.
Attached Files
File Type: txt Print Code.txt (22.1 KB, 8 views)
remya1000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-14-2012, 12:00 AM Re: VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width)
Experienced Talker

Posts: 39
Name: remya
Trades: 0
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.
remya1000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45504 seconds with 13 queries