2 Replies - 7846 Views - Last Post: 19 March 2013 - 11:10 PM Rate Topic: -----

#1 Lost_IdeA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-March 13

Printing Datagridview with crystal report in VB.NET problem

Posted 19 March 2013 - 02:45 AM

I was making a code for printing Datagridview all value(Scroll Able Form) to Crystal Report. I have search over the internet, at least i have the code to print.

Private Sub prtbtn_Click(sender As Object, e As EventArgs) Handles prtbtn.Click
        Dim ds As New DataSet
        Dim dt As New DataTable()
        dt = TryCast(datagridview1.DataSource, DataTable)
        ds.Tables.Add(dt) <<Error
        Printview.report1.SetDataSource(ds)
        Printview.rptview.ReportSource = Printview.report1
        Printview.rptview.Refresh() 'Refresh the report.
    End Sub


But, when i tried to click. I got

'table' argument cannot be null.

Does anyone know how to solve it?

Is This A Good Question/Topic? 0
  • +

Replies To: Printing Datagridview with crystal report in VB.NET problem

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Printing Datagridview with crystal report in VB.NET problem

Posted 19 March 2013 - 03:01 AM

Hi,

You can find some information about how to print datagridview values with Crystal report, here.
Was This Post Helpful? 0
  • +
  • -

#3 Lost_IdeA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-March 13

Re: Printing Datagridview with crystal report in VB.NET problem

Posted 19 March 2013 - 11:10 PM

Sorry for the link, i dont know what it means, cause i was newbie to crystal report. Beside that i have tried to add my code,

     Dim dt As New DataTable
        Dim dgvrow As System.Windows.Forms.DataGridViewRow
        Dim dgvcol As System.Windows.Forms.DataGridViewColumn
        For Each dgvcol In Me.datagridview1.Columns
            dt.Columns.Add(dgvcol.Name)
        Next
        For Each dgvrow In Me.datagridview1.Rows
            dt.Rows.Add(dgvrow)
        Next
        Dim i As Integer = 0
        Dim j As Integer = 0
        For i = 0 To Me.datagridview1.Rows.Count - 2
            For j = 0 To Me.datagridview1.Columns.Count - 2
                dt.Rows(i).Item(j) = Me.datagridview1.Rows(i).Cells(j).Value.ToString()
            Next
        Next
        ds.Tables.Add(dt)
        Printview.CryRpt1.SetDataSource(dt)<<error here

        Printview.Show()

        Printview.rptview.Refresh()


But, i got error. "The report has no tables."
Also, the processing is taking much time even i have PC corei3
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1