Page 1 of 3 123 LastLast
Results 1 to 40 of 89

Thread: DataGridPrinter - A class to print data grid in a nicely formatted way

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    DataGridPrinter - A class to print data grid in a nicely formatted way

    The DataGridPrinter is a class that you can add to your applications to print (or preview) a data grid (or DataGridView) in a nciely formatted way.

    The class allows you to control settings such as the header height, footer height, header font, grid font, footer font, grid line colour, header border colour, inter section spacing and so on.

    The class takes care of putting the grid headings at the top of each page and generating a new page if the grid rows exceed one page etc.

    Any comments or suggestions?
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by Merrion; Jan 24th, 2016 at 03:21 PM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    I have submitted an article explaining the what and how of this class here
    Last edited by Merrion; May 7th, 2009 at 01:53 AM. Reason: url fixed

  3. #3
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    I have used this, and this is fantastic....

    but can we print in landscape?
    If you find my thread helpful, please remember to rate me

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Yes - if you change the page layout (in print preview) then the columns and rows get recalculated to fit the page 'automatically'...

    New version (updated with the article) supports background colours for the grid elements.

    Am working on some more defect fixes and enhancements and will post the next release on this thread.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    New version - now has a property "PagesAcross" which allows you to overflow the grid across more than one page across...(users of excel know all about this functionality)
    Last edited by Merrion; Nov 2nd, 2009 at 03:04 AM. Reason: removed old code

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Option Strict version attached.

    (and it also prints all columns on the one page.... )
    Last edited by Merrion; Nov 4th, 2009 at 01:49 PM. Reason: To take account of the left margin :doh:

  7. #7
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Nice Sample Merrion.
    How could this work under Datagridview. I have tried to convert everything named datagrid to datagridview.The page setup works fine, but the print gives me errors in the functions
    getColumnHeadingText(),MappedColumnToBaseColumn
    Over datagrid's tablestyles and gridcolumnstyles

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    It will need to be rewritten to work for DataGridView which I will add to the list to do - I find it difficult to keep up with all the new tricks

  9. #9
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Here is a link to print a datagridview, but i have so far failed to convert it into vb.net.
    Will some one try it out!
    http://www.codeproject.com/csharp/da...iewprinter.asp

  10. #10
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Thanks to Berthold Simon, who converted the C# code.
    Attached Files Attached Files

  11. #11
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Thank You Merrion for the DataGridPrinter Class. How can we hide the GridLines.

    Regards,
    Binu

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    To hide the grid lines set .Gridpen = New Pen(Color.Transparent)

  13. #13
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Arrow DataGridPrinter -Help me Pls

    Sir,

    Thank you for replying me. I am a beginner for vb.net. Pls tell me how to set the column width in DatagridPrinter.

    Regards,
    Binu

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Column width is proportional to the column widths on the source datagrid control...

  15. #15
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Sir,

    The DataGridPrinter Very much helped me in my work.

    In DataGridPrinter the Column width is adjusting with the Page width. So the Column Data is Printing like 'Customer N...'. Pls help me to avoid this.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Column width is in the same proportions as the source data grid - if you make the column wider on the source grid it becomes wider on the print/preview grid.

    Column width is proportional to the .pagesAcross number - the more pages across your grid is set to, the wider each column can be made.

    So - increase your pages across setting and/or alter the column widths in the source data grid.

  17. #17

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    I downloaded the file from the post with:
    Thanks to Berthold Simon, who converted the C# code.
    .

    how do i use this in my project? i have a datagridview and a button. What do i need to do so that when the button is pressed the datagridview is printed? i.e how do i use what i just downloaded?

  18. #18
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    See the below article for a clear idea.

    http://www.thecodeproject.com/userit...ridPrinter.asp

  19. #19

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    broken link...

  20. #20

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    am i doing this right?:

    1. download the zip file
    2. add the .vb file to my project
    3. use code
    VB Code:
    1. Imports PRECIS.DataGridViewPrinter
    to import the class to the form im using it in
    4. put source code from readme into project:

    VB Code:
    1. Private Function SetupThePrinting() As Boolean
    2.         Dim MyPrintDialog As PrintDialog = New PrintDialog()
    3.  
    4.         MyPrintDialog.AllowCurrentPage = False
    5.         MyPrintDialog.AllowPrintToFile = False
    6.         MyPrintDialog.AllowSelection = False
    7.         MyPrintDialog.AllowSomePages = True
    8.         MyPrintDialog.PrintToFile = False
    9.         MyPrintDialog.ShowHelp = False
    10.         MyPrintDialog.ShowNetwork = False
    11.  
    12.         If MyPrintDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return False
    13.  
    14.         MyPrintDocument.DocumentName = "Customers Report"
    15.         MyPrintDocument.PrinterSettings = MyPrintDialog.PrinterSettings
    16.         MyPrintDocument.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings
    17.         MyPrintDocument.DefaultPageSettings.Margins = New Margins(40, 40, 40, 40)
    18.  
    19.        if MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes then
    20.            MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView, MyPrintDocument, true, true, "Customers", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true)
    21.        else
    22.            MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView, MyPrintDocument, false, true, "Customers", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true)
    23.        end if
    24.  
    25.        Return True
    26.     End Function
    27.  
    28.     Private Sub MyPrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles MyPrintDocument.PrintPage
    29.         Dim more As Boolean
    30.  
    31.         Try
    32.             more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
    33.             If more Then e.HasMorePages = True
    34.         Catch Ex As Exception
    35.             MessageBox.Show(Ex.Message & vbCrLf & Ex.StackTrace, MyConstants.CaptionFehler, MessageBoxButtons.OK, MessageBoxIcon.Error)
    36.         End Try
    37.     End Sub
    38.  
    39.     ' The Print Preview Button
    40.     Private Sub btnPrintPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
    41.         If SetupThePrinting() Then
    42.             Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
    43.             MyPrintPreviewDialog.Document = MyPrintDocument
    44.             MyPrintPreviewDialog.ShowDialog()
    45.         End If
    46.     End Sub
    47.  
    48.     ' The Print Button
    49.     Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
    50.     if SetupThePrinting() then MyPrintDocument.Print
    51.     end SUb

    If this is right, i am getting several errors.
    most say that MyPrintDocument and MyDataGridViewPrinter are not declared, so i have put
    VB Code:
    1. Dim MyPrintDocument As PrintDocument
    2.     Dim MyDataGridViewPrinter As DataGridViewPrinter
    at the top of the form. is this correct?

    also, in the line
    VB Code:
    1. MessageBox.Show(Ex.Message & vbCrLf & Ex.StackTrace, MyConstants.CaptionFehler, MessageBoxButtons.OK, MessageBoxIcon.Error)
    , i am getting the error that MyConstants is not declared...

    I am also getting Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types., relating to the line
    VB Code:
    1. Private Sub MyPrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles MyPrintDocument.PrintPage
    , and the MyPrintDocument from MyPrintDocument.PrintPage is underlined...

    any help on these would be greatfully recieved, or, if i am not doing this right, the correct way would also be helpful. ta.

  21. #21
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Arrow Re: DataGridPrinter - A class to print data grid in a nicely formatted way


  22. #22

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    thats a totally different piece of coding, and it's for datagrids, not datagridviews - i'm using vb 2005...
    Last edited by simonalexander2005; Aug 3rd, 2006 at 08:51 AM.

  23. #23
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    very powerful

    thank you , i will sure rate u for it

  24. #24
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Arrow Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    If GridPrinter Is Nothing Then
    GridPrinter = New DataGridPrinter(Me.dgReport)
    End If
    With (GridPrinter)
    .HeaderText = "Stock Report"
    .HeaderHeightPercent = 5
    .FooterHeightPercent = 0
    .HeaderPen = New Pen(Color.Transparent)
    .GridPen = New Pen(Color.Black)
    End With

    With Me.PrintPreviewDialog1
    .Document = GridPrinter.PrintDocument
    If .ShowDialog = DialogResult.OK Then
    GridPrinter.Print()
    End If
    End With



    It Shows Following Exception in the Line "If .ShowDialog = DialogResult.OK Then"

    ************** Exception Text **************
    System.InvalidCastException: Specified cast is not valid.
    at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
    at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

    Pls tell me how to solve this Problem.

  25. #25
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    i had also issues when i try to print datagird with custom column styles.

    it doesnt print and raises an exception , i dont have time to study well though

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    You need to put a breakpoint in the control's PrintPage event and step through what it is doing as the error is occuring there somewhere....let me know when you find the line that is the underlying cause of the error.

  27. #27
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Sir,
    Its not showing the print preview also. but it works in my last finished project.
    Pls help me

  28. #28
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    is the datagridprinter compatable with VS 2005 Express edition?
    its just i am tryin to use it in my project adn i have having difficulty as it is saying that datagrid isnt defined and so when i look at the code provided it isnt but if you hover over the text it says it is defined as 'DataGridPrinter.DataGridPrinter' so if i declare this manually it says in the decleratioin that 'DataGridPrinter.DataGridPrinter' isnt defined.
    Can someone tell me where i am going wrong

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    It was written using VB2005 and it does not use anything that is not present in the express edition. Make sure you are opening the solution file (*.sln) not one of the projects (*.vbp) as in the latter case the references might not be loaded...

  30. #30
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Smile Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Hi,

    Thank you for the DataGridView Printer, awesome work!!!

    I too had some problems getting it to work, but it was minor stuff so I posted the code below (You still need to add the Class to your project):

    Thank you!
    Funch

    Public Class Form1

    Dim cnStr As String = "Provider=SQLOLEDB;Initial Catalog=Reporting;Data Source=ncso-exch;"
    Dim myDataGridViewPrinter

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'DG.Rows.Clear()
    Dim rs As New ADODB.Recordset
    Dim strSQL As String = "select * from Userdata order by username"
    rs.Open(strSQL, cnStr)

    While Not rs.EOF
    DG.Rows.Add()
    DG.Rows(DG.Rows.Count - 1).Cells(0).Value = rs.Fields.Item("Username").Value.ToString.Replace("NCSO\", "")
    DG.Rows(DG.Rows.Count - 1).Cells(1).Value = rs.Fields.Item("MachineName").Value.ToString
    DG.Rows(DG.Rows.Count - 1).Cells(2).Value = rs.Fields.Item("IPAddress").Value.ToString
    DG.Rows(DG.Rows.Count - 1).Cells(3).Value = rs.Fields.Item("LastRun").Value.ToString
    DG.Rows(DG.Rows.Count - 1).Cells(4).Value = rs.Fields.Item("Version").Value.ToString
    DG.Rows(DG.Rows.Count - 1).Cells(5).Value = rs.Fields.Item("CMVersion").Value.ToString
    DG.Rows(DG.Rows.Count - 1).Cells(6).Value = rs.Fields.Item("DBServer").Value.ToString
    rs.MoveNext()
    End While
    rs.Close()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    End
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If SetupThePrinting() Then MyPrintDocument.Print()
    End Sub

    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

    If MyPrintDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return False

    MyPrintDocument.DocumentName = "Customers Report"
    MyPrintDocument.PrinterSettings = MyPrintDialog.PrinterSettings
    MyPrintDocument.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings
    'MyPrintDocument.DefaultPageSettings.Margins = New Margins(40, 40, 40, 40)

    If MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    MyDataGridViewPrinter = New DataGridViewPrinter(DG, MyPrintDocument, True, True, "Customers", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    Else
    myDataGridViewPrinter = New DataGridViewPrinter(DG, MyPrintDocument, False, True, "Customers", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    End If

    Return True
    End Function

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

    Try
    more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
    If more Then e.HasMorePages = True
    Catch Ex As Exception
    MessageBox.Show(Ex.Message & vbCrLf & Ex.StackTrace, "caption", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End Sub

    Private Sub btnPrintPreview_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
    If SetupThePrinting() Then
    Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
    MyPrintPreviewDialog.Document = MyPrintDocument
    MyPrintPreviewDialog.ShowDialog()
    End If
    End Sub
    End Class

  31. #31
    Junior Member
    Join Date
    Jul 2007
    Posts
    23

    Question Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    I tried using the files from the original post in order to print the output of my datagrid, but I get:

    System.InvalidCastException: Specified cast is not valid

    This is the line specified in the DataGrid class

    For nextLine = _CurrentPrintGridLine To Min((_CurrentPrintGridLine + RowsPerPage(_PrintFont, e.Graphics)), CType(_DataGrid.DataSource, System.Data.DataTable).DefaultView.Count)

    This is the code I am using:

    Code:
    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
    
    'Button that prints the datagrid
            If GridPrinter Is Nothing Then
                GridPrinter = New DataGridPrinter(Me.dgInventory)
            End If
    
            Try
                With Me.printDia  'printDia is PrintPreviewDialogue added manually
                    .Document = GridPrinter.PrintDocument
                    If .ShowDialog = DialogResult.OK Then
                        GridPrinter.Print()
                    End If
                End With
            Catch ex As System.InvalidCastException
                MsgBox(Convert.ToString(ex))
            End Try
    
        End Sub
    Code:
     Private Sub frmInvReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'Create connection to Database
            Dim connStr As String
            Dim dbObjConn As New OleDb.OleDbConnection
            connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=InventoryManagement.mdb;"
            dbObjConn.ConnectionString = connStr
    
            'create SQL statement
            Dim selectString As String = "Select * from Products"
    
            'create DataAdapter
            Dim sqlDA As New OleDb.OleDbDataAdapter(selectString, connStr)
    
            'Fill dataset
            Try
                dbObjConn.Open()
    
                Dim ds As New Data.DataSet
                sqlDA.Fill(ds, "Products")
                dgInventory.CaptionText = "Inventory Report"
                dgInventory.DataSource = ds.DefaultViewManager
            Catch ex As OleDb.OleDbException
                MsgBox(Convert.ToString(ex))
            Finally
                dbObjConn.Close()
            End Try
        End Sub

    So the datagrid is filled in properly, but when I try printing I get the cast error. If you need the whole project or more information please let me know.
    Thanks

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Yup - it is because the data source of your grid is a DataSet rather than a DataTable --- the code needs to be altered to cater for this possibility...

  33. #33
    Junior Member
    Join Date
    Jul 2007
    Posts
    23

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Well, I started using a dataTable but the examples I was lookign at all end up binding using a dataSet in the end. I'll show you the example I was following to do a dataTable instead.

    Code:
     Dim Table1 As DataTable
                Table1 = New DataTable("Products")
                Dim Row1 As DataRow
                Dim description As DataColumn = New DataColumn("description")
                description.DataType = System.Type.GetType("System.String")
                Table1.Columns.Add("description")
    
                Row1 = Table1.NewRow()
                'declaring a new row
                Row1.Item("description") = "blah blah blah"
                Table1.Rows.Add(Row1)
    so far so good it seems. Then the example finishes off by doing this

    Code:
               Dim ds As New Data.DataSet
                ds.Tables.Add(Table1)
                dgInventory.SetDataBinding(ds, "Products")
    which basically brings me to the exact same problem lol. Can someone kinda guide me in the right direction? *blushes*

  34. #34
    Junior Member
    Join Date
    Jul 2007
    Posts
    23

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Gah nvm, I just did

    Code:
    dgInventory.DataSource = Table1
    and voila, works. Thanks a lot Merrion

  35. #35
    Member
    Join Date
    Aug 2007
    Posts
    59

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Is it possible to use the zipped code in vb.net 2003 for datagrids?

  36. #36
    Lively Member
    Join Date
    Jan 2006
    Posts
    87

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    How can i set the paper size?
    I mean, make the paper half of its height?


    Im using the datagridview printer class
    thanks.
    I Hope I Could be Great Like You

  37. #37

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Yet another version.

    New in this release:
    (1) Can work with the DataGrid or DataGridView control
    (2) Raises an event to allow custom colouring of a data grid cell e.g.:-
    Code:
        Private Sub GridPrinter_QueryCellFormat(ByVal sender As Object, ByVal e As QueryCellFormatEventArgs) Handles GridPrinter.QueryCellFormat
    
            '\\ Top 2 clubs go up
            If e.RowNumber <= 2 Then
                e.BackgroundColour = Brushes.AliceBlue
            End If
    
            If e.ColumnNumber = 0 Then
                If e.CellData.ToString = "Grimsby" Then
                    e.TextColour = Brushes.RoyalBlue
                End If
            End If
    
            '\\ Bottom 2 columns relegation
            If e.RowNumber >= 23 Then
                e.BackgroundColour = Brushes.LightGray
            End If
        End Sub
    (3) Raises an event to allow you to change the actual text in a cell:
    Code:
        Private Sub GridPrinter_QueryCellData(ByVal sender As Object, ByVal e As QueryCellDataEventArgs) Handles GridPrinter.QueryCellData
    
            If e.ColumnNumber > 0 And e.CellText = "0" Then
                e.CellText = "Zero"
            End If
        End Sub
    Last edited by Merrion; Nov 4th, 2009 at 01:50 PM.

  38. #38
    Member
    Join Date
    Feb 2006
    Location
    Sydney, Australia
    Posts
    42

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    My mistake, sample can be run from the project file in VS 2005.

    Thanks,
    Adam.

    Hi Merrion,

    Latest version appears to be in VS 2008, any chance of getting it in VS 2005?

    Cheers,
    Adam.
    Last edited by adam.syd; Sep 13th, 2007 at 09:05 PM.

  39. #39

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Oops - because VS2008 is so much nicer a development environment I have been using it for all my code - guess i forgot to roll this one back for "publication"...

  40. #40
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213

    Re: DataGridPrinter - A class to print data grid in a nicely formatted way

    Thanks a lot for sharing this great work, Merrion!

    I d/l'd your latest version and got it to work right off!
    Last edited by GSIV; Sep 21st, 2007 at 09:42 PM.

Page 1 of 3 123 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width