Link DataGridView to CrystalDecisions Report
In my Visual Basic 2010 project, I have a form named "frmViewReport" containing a CrystalDecisions CrystalreportViewer which I plan to use to display all my reports. In my report generating form I have DataGridView named "PersonnelDataGridView" which is being populated correctly. I have designed the report named "RptPersonnel.rpt" with headers and other details as required. But I am unable to link the DataGridView with the report as a result when I show the report only the header is getting displayed. How do I link the DataGridView with the CystalReport in code??
Re: Link DataGridView to CrystalDecisions Report
I don't use Crystal Reports but I'd be very surprised if you couldn't use a DataSet/DataTable as the source. Assuming you can, just bind the same DataSet/DataTable to your DataGridView. If you use the same source for both then they will obviously display the same data.
Re: Link DataGridView to CrystalDecisions Report
There is a TableAdapter named "PersonnelTableAdapter" which is bound to the DataGridView. But how do I link to the Crystal Report in code??
Re: Link DataGridView to CrystalDecisions Report
Quote:
Originally Posted by
Eager_Beever
There is a TableAdapter named "PersonnelTableAdapter" which is bound to the DataGridView.
No there isn't. Table adapters don't contain data. They open connections to a database to retrieve or save data. That data is stored in a DataTable that is itself in a DataSet and that's what's bound to the grid.
Quote:
Originally Posted by
Eager_Beever
But how do I link to the Crystal Report in code??
I don't know because, as I said, I don't use CR but if I wanted to know then I'd do the bleeding obvious and search the web for datatable crystal reports or the like.
Re: Link DataGridView to CrystalDecisions Report
Here's an example of using a dataset as a datasource for CR,
Code:
Dim ds As New WaterTablesDataSet
Dim taG As New WaterTablesDataSetTableAdapters.groupsTableAdapter
Dim taL As New WaterTablesDataSetTableAdapters.lotsTableAdapter
Dim taU As New WaterTablesDataSetTableAdapters.usersTableAdapter
taG.FillByNoDoubles(ds.groups)
taL.FillByNoDoubles(ds.lots)
taU.Fill(ds.users)
Dim rpt As New rptLateralAcreageReport
rpt.SetDataSource(ds)
rpt.SummaryInfo.ReportAuthor = clsCoInfo.CompName
rpt.SummaryInfo.ReportTitle = "Lateral Acreage Report"
Dim frm As New frmReports
frm.CrystalReportViewer1.ReportSource = rpt
frm.Show()
The CR datasource can also be set to a single datatable. This example uses the dataset because the report was designed using two tables.