Results 1 to 16 of 16

Thread: Printing problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Printing problem

    Hi ,

    Im trying to retrieve a class for printing I had used a couple of year ago, which aint working now. the class is attached cos its too long to post it here.
    can someone help it out with this please.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            GridPrinter = New DataGridPrinter(Me.DataGrid4)
           If GridPrinter Is Nothing Then
    
            End If
    
          With GridPrinter
               .HeaderText = lblItemsCounted.Text
               (Me.ComboBox_ColumnHeaderBrush.SelectedItem, Brush)
                .PagesAcross = 1
               .PrintDocument.Print()
    
           End With
       End Sub
    Attached Files Attached Files
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing problem

    1. This thread belongs in the VB.NET forum because it has nothing to do with databases. the fact that the data in the grid may have come from a database in the first place is hardly relevant.

    2. "It ain't working, please help." What sort of response do you really expect to that? Perhaps an explanation of exactly what you're trying to do, how you're trying to do it and what actually happens might be useful.

    3. I assume that this class is from Merrion's CodeBank thread. If that's the case then maybe that would be the place to ask a question about it first.


    [Thread moved — Mod]
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    wow! I dont remember exactly the source of the class, it been a couple of year , 2003 !

    Now for the errors.
    ----------------------------------------------------
    1.. At runtime on

    Code:
    .PrintDocument.Print()
    I get this error:

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

    -----------------------------------------------------
    error 2

    Warning 1 Function 'GetColumnHeadingText' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. C:\Visual Studio 2005..............\DataGridPrinter.vb
    ------------------------------------------


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

  4. #4
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Printing problem

    Quote Originally Posted by angelica
    Unable to cast object of type 'System.Data.DataSet' to type 'System.Data.DataTable'.
    May be you have bound DataGrid to DataSet and the class module that prints the grid is expecting a DataTable. Try to bind the DataGrid to a DataTable.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing problem

    1. My guess is that the code is casting, either implicitly or explicitly, the DataSource of the grid as type DataTable. If you've bound a DataSet and set the DataMember rather than binding a DataSet then you'll have to adjust the code accordingly. Perhaps adjusting the printing class to handle either, and perhaps a BindingSource too, would be the way to go.

    2. Easy fixed. Just read the code and edit to make sure that a value is always returned by the method. The best way to do that is to have one and only one Return statement at the very end of the method. You return a local variable that you have set at one or more points within the method. If it's OK to return Nothing then you should initialise that variable to Nothing. If it's not OK to return Nothing then you need to make sure that, no matter what path execution takes through the method, a value will always be assigned to that variable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Printing problem

    Can't be a harm to get the most recent DataGridPrinter code while your are doing this.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing problem

    Quote Originally Posted by Merrion
    Can't be a harm to get the most recent DataGridPrinter code while your are doing this.
    Given that I mentioned your name and the CodeBank in the first reply, I would have hoped that going to that thread would be the next move.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    Hey,

    Why is it I get these errors. Im using visual studio 2005.

    I have downloaded Merion's most recent DataGridPrinter.

    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
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Printing problem

    try this. i fixed the errors but didn't test it:
    Attached Files Attached Files
    Last edited by .paul.; Oct 4th, 2008 at 02:59 PM.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Printing problem

    read post #9 again. i fixed the latest version now

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    Hey .Paul,

    Many thanks for your code. The code you sent me works fine on its own except for a small error on the showdialog which Ive fixed. However since I am using Datasets and Dataviews it doesnt work on mine.

    Can you fix it for me please to work on both of these. It'spretty urgent cos I need to send this project by tomorrow. Much aqppreciated if you can help.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Printing problem

    Datasets and Dataviews aren't my speciality.
    i'd recommend changing your project to something it will work with

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    thanks Paul,

    Can someone else help please?
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    My databinding is done this way. The printing is being activiated but it needs to output through a table as the specifications in the class of .Paul above goes.


    Does anybody knows how I can alter either the class or this method to print please.


    Code:
    sing cmd As New SqlClient.SqlCommand(query, MyConn)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.Add("@success", SqlDbType.Int)
                    cmd.Parameters("@success").Direction = ParameterDirection.Output
                    cmd.Parameters.AddWithValue("@startDate", DateTimePicker2.Value.Date)
                    cmd.Parameters.AddWithValue("@endDate", DateTimePicker1.Value.Date)
    
    
                    MyConn.Open()
    
                    Using mMySqlDataAdapter As New SqlClient.SqlDataAdapter(cmd)
                        Using mDataSet As New DataSet
                            mDataSet.Clear()
                            mMySqlDataAdapter.Fill(mDataSet, "tb_LAbook")
                            mDataView = New DataView
                            mDataView.Table = mDataSet.Tables("tb_LAbook")
                            lblNo.Text = mDataView.Count
                        End Using
                    End Using
                End Using
    
                With DataGrid5
                    .DataSource = mDataView
                    ' .AutoResizeRows() '  resize columnsfor user resizing facility
                End With
    Last edited by angelica; Oct 6th, 2008 at 12:30 AM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  15. #15
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Printing problem

    Try the code given below. I have used Table instead of a DataView.

    vb.net Code:
    1. Using cmd As New SqlClient.SqlCommand(query, MyConn)
    2.     cmd.CommandType = CommandType.StoredProcedure
    3.     cmd.Parameters.Add("@success", SqlDbType.Int)
    4.     cmd.Parameters("@success").Direction = ParameterDirection.Output
    5.     cmd.Parameters.AddWithValue("@startDate", DateTimePicker2.Value.Date)
    6.     cmd.Parameters.AddWithValue("@endDate", DateTimePicker1.Value.Date)
    7.  
    8.     MyConn.Open()
    9.  
    10.     Using mMySqlDataAdapter As New SqlClient.SqlDataAdapter(cmd)
    11.         Using mDataSet As New DataSet
    12.             mDataSet.Clear()
    13.             mMySqlDataAdapter.Fill(mDataSet, "tb_LAbook")
    14.             'mDataView = New DataView
    15.             'mDataView.Table = mDataSet.Tables("tb_LAbook")
    16.             'lblNo.Text = mDataView.Count
    17.             DataGrid5.DataSource = mDataSet.Tables("tb_LAbook")
    18.             lblNo.Text = mDataSet.Tables("tb_LAbook").Rows.Count
    19.         End Using
    20.     End Using
    21. End Using

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing problem

    Thanks Deepak works nicely now. Cheers
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

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