Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 89

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

  1. #41
    Addicted Member
    Join Date
    May 2007
    Posts
    166

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

    i just tried your DataGridPrinter Class to print my dataGrid.

    and printer is not directly connected to my machine. printer is connected to one of the network machine. and i can access that printer from my machine.

    but for me while running this program its creating an error.
    An unhandled exception has occurred in your application. if you click Continue, the application will ignore this error and attempt to continue. If you clicknQuit, the application will be shut down immediately.

    Specified Cast in Not Valid.
    if you have any idea what's wrong with this program, please let me know...Please help me....

    thanks in advance....
    Attached Images Attached Images  
    Last edited by remya1000; Oct 17th, 2007 at 10:43 AM.

  2. #42

    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

    As per the post a few above this, it falls over if the datasource of the datagrid is something other than a Datatable....because it can't get the table column names.

  3. #43
    Addicted Member
    Join Date
    May 2007
    Posts
    166

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

    its working perfectly...

    for me problem occurs because i'm not taking the datatable values to datagrid. before i was taking values from dataview to datagrid. when i tried to called datatable values to datagrid... then it works perfectly....

    thanks a lot for your reply and for this post... its a good example and sure i will rate this post...

    excelent work.... once again thanks a lot for this post....

  4. #44
    New Member
    Join Date
    Dec 2007
    Posts
    1

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

    is there a way to use DataGridViewPrinter or DataGridPrinter class to print more than 1 datagridview controls ? I can have 3-5 on the same winform.

    Thnxs in advance

  5. #45

    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

    If you don't require the subsequent grid(s) to start on the same page as the fist grid ends on you could just have one DataGridprinter class for each grid on your form and call their Print methods in sequence.

    You would only be able to preview one grid at a time, however.

  6. #46
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

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

    Merrion your sample is very nice...I like it but do you have any idea if i use listview instead of datagrid? I am using a listview right now on my current program. Could you give me an idea on how to do that? or what if i want to print on my textbox..Thanks in advance Merrion..Have a nice day and God Bless....
    Last edited by shyguyjeff; Feb 6th, 2008 at 09:54 PM.

  7. #47
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    752

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

    Hey people was wondering someone could offer me some help please

    The program keeps throwing that error, I do have a datatable and im using vb 2003.

    Any help or suggestions? Thanks
    Attached Images Attached Images  

  8. #48

    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'd need to expand the [Details] button so that we can see what is occuring...

  9. #49
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    752

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

    Hey I found out what the problem was, during the form load event I had my own table styles and I set some of the values to 0 when it should have been 1.

    Working now perfectly thanks buddy

  10. #50
    New Member
    Join Date
    Apr 2008
    Posts
    1

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

    I'm missing something, my PrintPreview comes up empty? I'm using a DataGridView.
    My Code Code:
    1. [CODE]
    2. #Region "Private members"
    3.     Private WithEvents GridPrinter As DataGridPrinter
    4. #End Region
    5.  
    6. Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
    7.         GridPrinter = New DataGridPrinter(Me.MfgCostBDDataGridView)
    8.         With Me.PrintPreviewDialog1
    9.             .Document = GridPrinter.PrintDocument
    10.             If .ShowDialog = DialogResult.OK Then
    11.                 GridPrinter.Print()
    12.             End If
    13.         End With
    14.     End Sub[/CODE]

    thanks

  11. #51
    Member
    Join Date
    Dec 2006
    Location
    Connecticut
    Posts
    40

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

    I'm trying to use this class but it doesn't work. When I run my program the user has to click a button to show the data from the database into a datagrid. If the user doen't click that button (there's nothing in the datagrid) then the print button works but there's nothing to print - it's just a blank page. But if there's data in the datagrid then the user clicks print then the debuggin stops at this line:

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

    and it says

    InvalidCastException was unhandled by user code

    Unable to cast object of type 'System.Data.DataSet' to type 'System.Data.DataTable'

    What does that mean or how do i fix that?

  12. #52

    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 means you need to set the DataGrid's DataSource member to a Datatable...
    (as per the post Oct 17th, 2007 05:02 PM)

  13. #53
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

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

    Quote Originally Posted by Merrion
    The DataGridPrinter is a class that you can add to your applications to print (or preview) a data grid 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?
    I am using VB6. When I try to open it I coudn't. How can I use it in my program to get the print from a DataGrid?

    Thanks

  14. #54
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

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

    Quote Originally Posted by Merrion
    The DataGridPrinter is a class that you can add to your applications to print (or preview) a data grid 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?
    Hi, I am using VB6. I have downloaded the zip file (DataGridPrinter_src)and unzipped it. But I cannot pen it. How can I use it in my program to get the print from a DataGrid?


    Thanks
    Last edited by VBLearner6; May 15th, 2008 at 09:19 AM.

  15. #55
    Member
    Join Date
    Dec 2006
    Location
    Connecticut
    Posts
    40

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

    Quote Originally Posted by Merrion
    It means you need to set the DataGrid's DataSource member to a Datatable...
    (as per the post Oct 17th, 2007 05:02 PM)

    How do I do that??
    I'm Using Microsoft Visual Basic 2008 Express Edition

  16. #56

    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

    Start from Post 31...

  17. #57
    Addicted Member
    Join Date
    May 2008
    Posts
    122

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

    ....
    Last edited by robyn.berry; Jun 12th, 2008 at 03:44 AM.

  18. #58

    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 would need to use Graphics.DrawImage to print the picture in the PrintPage handler.

  19. #59
    New Member
    Join Date
    Feb 2008
    Posts
    10

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

    excellent work merrion!

    thank you thank you!!!

    i just moved to vb.net (08)

    and dunno what to do to get my printworks done!


    i have some questions though ,,

    you can set the width of data displayed by adjusting column width (hehehe they asked you many times for this column thing) which is now proportional to your source grid.

    how can you increase the size of your cell heigth?

    i have data like (lets pretend that is in the cell) :

    hello
    world <- a part of this is seen

    please help me increase the row width ... thank you

    i have a feeling that this is possible, i only not know how to...


    also,

    in the cell gutter, it is 1-10 right? i set it to ten , and it generates an error
    I looked at ur code and the condition is

    Code:
    if Value <0 OrElse Value >=10
    maybe it needs a tweak? correct me if im wrong



    many thanks merrion! your datagrid printer makes printing so easy!

  20. #60
    Lively Member
    Join Date
    Sep 2008
    Location
    TX
    Posts
    67

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

    Hi Merrion,

    Thanks for your code. One question: How do I increase the margin of the output?

    Thanks, Dave

  21. #61
    Lively Member
    Join Date
    Sep 2008
    Location
    TX
    Posts
    67

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

    Well,

    The solution was easy enough. Figured I would post for others like me. Notice the margin assignment below.

    Code:
            With Me.PrintPreviewDialog1
                .Document = GridPrinter.PrintDocument
                .Document.DefaultPageSettings.Margins.Left = 50
                .Document.DefaultPageSettings.Margins.Right = 50
                If .ShowDialog = DialogResult.OK Then
                    GridPrinter.Print()
                End If
            End With
    Dave

  22. #62
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

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

    Hey,

    Why is it I get these errors. Im using visual studio 2005. Is there a way I can solve this printing problem please




    Code:
    Warning	2	Function without an 'As' clause; return type of Object assumed.	C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb	410	21	DataGridPrinter
    
    Warning	3	Unused local variable: 'x'.	C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb	419	13	DataGridPrinter
    
    Warning	4	Unused local variable: 'y'.	C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb	419	26	DataGridPrinter
    
    Warning	5	
    Function 'DrawCellString' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb	441	5	DataGridPrinter
    Last edited by angelica; Oct 4th, 2008 at 03:31 AM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  23. #63

    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

    Warning 2 Function without an 'As' clause; return type of Object assumed. C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb 410 21 DataGridPrinter
    Because I am human and fallible I didn't put any return type on the function declared on line 410. In fact it should probably be changed to be a sub not a function?

    Warning 3 Unused local variable: 'x'. C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb 419 13 DataGridPrinter
    Because I am human and fallible I didn't remove the variable declaration 'x' on line 419 when I removed the code that used it. It can be removed.

    Warning 4 Unused local variable: 'y'. C:\DataGridPrinter_src\DataGridPrinter\DataGridPrinter.vb 419 26 DataGridPrinter
    Because I am human and fallible I didn't remove the variable declaration 'y' on line 419 when I removed the code that used it. It can be removed.

    Warning 5
    Function 'DrawCellString' doesn't return a value on all code paths. A null reference exception could
    Because I am human and fallible etc.

  24. #64
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

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

    Quote Originally Posted by GSIV
    Thanks a lot for sharing this great work, Merrion!

    I d/l'd your latest version and got it to work right off!
    Hi,

    Can I use it with VB6 application so that I can use it in my vb6 project to print the grids?

  25. #65
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

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

    HI Merrion,

    Can you please update the whole thing and is it possible for me (not being so much of an expert in vb.net) to print from a dataset and dataview?

    Thanks and keep up the good work on this Forum.

    cheers
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  26. #66
    Member
    Join Date
    Jul 2008
    Posts
    61

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

    I am having a bit of a strange problem. I am trying to Print out a Datagridview using a PrintPreviewDialog. The Datagridview contains the contents of a table.

    If I populate the table manually (row by row) everything is fine. If I populate the table using an access database and an OleDbDataReader then I can only see (and subsequently print out) the first page.

    Someone mentioned in an earlier thread that the problem might be resolved by setting the e.HasMorePages property to true. Could someone tell me how to do this

    thanks
    Last edited by micki_free; Oct 27th, 2008 at 09:07 AM.

  27. #67
    Member
    Join Date
    Jul 2008
    Posts
    61

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

    This is the code that works

    Code:
     Dim MyTable As New DataTable
    
            MyTable.Columns.Add(New DataColumn("Team", GetType(String)))
            MyTable.Columns.Add(New DataColumn("Played", GetType(Integer)))
            MyTable.Columns.Add(New DataColumn("Goal Difference", GetType(Integer)))
            MyTable.Columns.Add(New DataColumn("Points", GetType(Integer)))
    
    
            MyTable.Rows.Add(New Object() {"Shrewsbury", 4, 3, 9})
            MyTable.Rows.Add(New Object() {"Chester", 4, 5, 8})
      
            DataGridView1.DataSource = MyTable
            If GridPrinter Is Nothing Then
                GridPrinter = New DataGridPrinter(Me.DataGridView1)
            End If
    
            'setting properties of dgview (after adding gridprinter )
            With GridPrinter
                .HeaderText = CStr("Report Dated - " & Today)
                .HeaderHeightPercent = CInt(5)
                .FooterHeightPercent = CInt(0)
                .InterSectionSpacingPercent = CInt(3)
                .PagesAcross = CInt(2)
            End With
    
            'printpreview prinout
            With Me.PrintPreviewDialog1
                .Document = GridPrinter.PrintDocument
                If .ShowDialog = DialogResult.OK Then
                    GridPrinter.Print()
                End If
            End With
    This is the code that doesn't work

    Code:
     Dim MyTable As New DataTable
    
            OleDbCommand1.CommandText = "SELECT Incident_ID, Incident_Date, Incident_Time, Location, Incident_Type, What_Happened, Affected_Individual, Police_Involvement, Crime_Number, Remedial_Action, Assailant FROM AccidentIncident"
            OleDbCommand1.Parameters.AddWithValue("@Incident_ID", "1")
            Dim reader As OleDbDataReader = OleDbCommand1.ExecuteReader()
            MyTable.Load(reader)
            reader.Close()
    
            DataGridView1.DataSource = MyTable
            If GridPrinter Is Nothing Then
                GridPrinter = New DataGridPrinter(Me.DataGridView1)
            End If
    
            'setting properties of dgview (after adding gridprinter )
            With GridPrinter
                .HeaderText = CStr("Report Dated - " & Today)
                .HeaderHeightPercent = CInt(5)
                .FooterHeightPercent = CInt(0)
                .InterSectionSpacingPercent = CInt(3)
                .PagesAcross = CInt(2)
            End With
    
            'printpreview prinout
            With Me.PrintPreviewDialog1
                .Document = GridPrinter.PrintDocument
                If .ShowDialog = DialogResult.OK Then
                    GridPrinter.Print()
                End If
            End With
    Last edited by micki_free; Oct 27th, 2008 at 09:07 AM.

  28. #68
    New Member
    Join Date
    Dec 2009
    Posts
    1

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

    I am using Merrion's method for printing the contents of my datagridview. It works great. I do have one question though. With my data grid view, I have set the text that shows up for each row using DataGridView1.Rows(x).HeaderCell.Value. Is there a way to have these text items also show up in the printing of the datagridview contents?

    Thanks!

  29. #69
    Member
    Join Date
    Jan 2010
    Posts
    41

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

    Quote Originally Posted by micki_free View Post
    This is the code that works

    Code:
            If GridPrinter Is Nothing Then
                GridPrinter = New DataGridPrinter(Me.DataGridView1)
            End If
    
            'setting properties of dgview (after adding gridprinter )
            With GridPrinter
                .HeaderText = CStr("Report Dated - " & Today)
                .HeaderHeightPercent = CInt(5)
                .FooterHeightPercent = CInt(0)
                .InterSectionSpacingPercent = CInt(3)
                .PagesAcross = CInt(2)
            End With
    
            'printpreview prinout
            With Me.PrintPreviewDialog1
                .Document = GridPrinter.PrintDocument
                If .ShowDialog = DialogResult.OK Then
                    GridPrinter.Print()
                End If
            End With
    I'm trying to use this code in VB.NET 2008 and it has no clue what 'GridPrinter' is. Am I missing something? was I supposed to import a class or something? Thanks for any help.

    Name 'GridPrinter' is not declared.
    Type 'DataGridPrinter' is not defined.

  30. #70
    Lively Member
    Join Date
    Sep 2008
    Location
    TX
    Posts
    67

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

    Look at post #50 in this thread as it defines GridPrinter.

    But, if you have DataGridPrinter undefined, then you have not included the reference to your solution.

    I would suggest go back and read Merrions post. There is also more info at the CodeProject on his package.

  31. #71
    Member
    Join Date
    Jan 2010
    Posts
    41

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

    Alright, I took care of those errors but I have a slight issue

    The class says it can't convert my DataGridViews to DataGrids...so this class was made for vb 2005. I tried setting it to DataGridView instead of DataGrid but TableStyles no longer exists in the DataGridView

    Value of type 'System.Windows.Forms.DataGridView' cannot be converted to 'System.Windows.Forms.DataGrid'.
    Last edited by Rando; Feb 4th, 2010 at 03:58 PM.

  32. #72
    Lively Member
    Join Date
    Sep 2008
    Location
    TX
    Posts
    67

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

    Come on now....

    A line like this does define a variable.

    Private WithEvents GridPrinter As DataGridPrinter

  33. #73
    Member
    Join Date
    Jan 2010
    Posts
    41

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

    I have a temporary work around... I copied the DataGrid from his VB 2003 document and pasted it into my VB 2008 document. I've hidden it outside of my form and the printer class is feeding from that DataGrid. If anyone knows how to fix it for a DataGridView, that would be great.

  34. #74
    Member
    Join Date
    Jan 2010
    Posts
    46

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

    I added this lines in the form load of DataGridPrinter by Merrion

    added code Code:
    1. Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Network_Info.mdb"
    2.         Dim myConnection As OleDbConnection = New OleDbConnection
    3.         myConnection.ConnectionString = connString
    4.         ' create a data adapter
    5.         Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select DateRecorded As [Date Recorded], Format([TimeRecorded],'HH:MM:SS AM/PM') As [Time Recorded], Computer_Name As [Computer Name], Fastest_Download_Speed & ' Kb/s' As [Fastest Download Speed] , Fastest_Upload_Speed & ' Kb/s' As [Fastest Upload Speed], Average_Download_Speed & ' Kb/s' As [Average Download Speed], Average_Upload_Speed & ' Kb/s' As [Average Upload Speed], Total_Downloads & ' KB' As [Total Downloads], Total_Uploads & ' KB' As [Total Uploads], IP_Address, ElapsedTime As [Elapsed Time] from Computer_Connection_Info Order by DateRecorded, TimeRecorded", myConnection)
    6.         ' create a new dataset
    7.         Dim ds As DataSet = New DataSet
    8.         ' fill dataset
    9.         da.Fill(ds, "Computer_Connection_Info")
    10.         ' write dataset contents to an xml file by calling WriteXml method
    11.         ' Attach DataSet to DataGrid
    12.         DataGrid1.DataSource = ds.DefaultViewManager

    But I always get an error in these lines:

    code Code:
    1. For nextLine = _CurrentPrintGridLine To Min((_CurrentPrintGridLine + RowsPerPage(_PrintFont, e.Graphics)), CType(_DataGrid.DataSource, System.Data.DataTable).DefaultView.Count)
    2.             Call PrintGridLine(e, nextLine)
    3.         Next

    It says:

    Unable to cast object of type 'System.Data.DataViewManager' to type 'System.Data.DataTable'.

    I really don't understand what's going wrong.

  35. #75

    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

    The DataGridPrinter only prints dataGrids whos data source is a DataTable.

    Code:
    DataGrid1.DataSource = ds.Tables(0)
    See post 31.

  36. #76
    Member
    Join Date
    Jan 2010
    Posts
    46

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

    Quote Originally Posted by Merrion View Post
    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.
    where exactly are you gonna do this? change the page layout to landscape.

  37. #77
    Member
    Join Date
    Jan 2010
    Posts
    46

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

    Quote Originally Posted by korae View Post
    where exactly are you gonna do this? change the page layout to landscape.
    I already figured it out, This is what I did:

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

  38. #78
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    420

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

    I wonder if someone could possibly assist, I am very new to VB (2008 Express) and am having some difficulty I am trying to print the contents of a DataGridView1 which has its source defined as Me.DataGridView1.DataSource = config.Tables(0). With config being a dataset that has been previously filled.

    I have imported the DataGridViewPrinter VB code into the project.

    With the actual form I have added Imports appname.DataGridViewPrinter to the top of the form that displays the datagrid.

    I have also added the code described in post #20 and have the same errors. I have corrected by adding the following to the form that display & Prints the dataview
    Code:
       
          Dim MyPrintDocument As PrintDocument
          Dim MyDataGridViewPrinter As DataGridViewPrinter

    However, I am still getting 'MyPrintDocument.' , 'MyDataGridViewPrinter.', MyDataGridView.' & 'MyConstants.' as Name is not declared


    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(MyDataGridView, MyPrintDocument, True, True, "Customers", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    Else
    MyDataGridViewPrinter = New DataGridViewPrinter(MyDataGridView, MyPrintDocument, False, True, "Customers", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    End If
    Can someone please assist and explain what I am doing wrong.

  39. #79
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    420

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

    I have managed to resolve the issue with MyprintDocument & MyDataGridViewPrinter not being declared, but within the DIM statement
    Code:
    Dim MyPrintDocument As PrintDocument
    Printdocument is Now not defined.

  40. #80

    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 tell the .NET framework where to fiund the PrintDocument class.

    Try:-


    Code:
    Dim MyPrintDocument As System.Drawing.Printing.PrintDocument

Page 2 of 3 FirstFirst 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