Open Crystal Report in Winform
You're using the wrong classes/controls for Crystal Reports.
Place a CrystalReportViewer
control on your form. Although with later versions of Visual Studio you have to download it separately, it was still shipped with VS2008.
If you don't see it in your toolbox, right-click anywhere in your toolbox and click "Choose Items...".
After checking it and pressing OK, it should be added to your toolbox. Remove your existing report control and drop a crystal report viewer on the form:
The necessary crystal references will be added to your project when you drop the viewer on it.
Add this using
directive to the top of your code-behind:
using CrystalDecisions.CrystalReports.Engine;
Then load your report into the viewer:
var cryRpt = new ReportDocument();
cryRpt.Load(@"C:\Users\Ahsan\Desktop\PROJECT INVENTORY SOFTWARE\InventorySoftware\InventorySoftware\CrystalReport1.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
EDIT:
Change the targeted framework from .NET Framework 4 Client Profile to .NET Framework 4:
Jack Frost
Updated on June 04, 2022Comments
-
Jack Frost almost 2 years
I've created a crystal report then after creating it, I've created a winform where I've import crystal report library (shown in code) and used a report viewer to view the report but i not able to view the report, the code, i am new with Crytal Reports, the code I've done is :
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CrystalDecisions.CrystalReports.Engine; namespace InventorySoftware { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.reportViewer1.RefreshReport(); } private void button1_Click(object sender, EventArgs e) { //string ReportSources = ""; ReportDocument cryRpt = new ReportDocument(); cryRpt.Load("C:\\Users\\Ahsan\\Desktop\\PROJECT INVENTORY SOFTWARE\\InventorySoftware\\InventorySoftware\\CrystalReport1.rpt"); reportViewer1.ReportSource = cryRpt; reportViewer1.Refresh(); } } }
it's giving error at
reportViewer1.ReportSource = cryRpt;
and the error isError 1 'Microsoft.Reporting.WinForms.ReportViewer' does not contain a definition for 'ReportSource' and no extension method 'ReportSource' accepting a first argument of type 'Microsoft.Reporting.WinForms.ReportViewer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ahsan\Desktop\PROJECT INVENTORY SOFTWARE\InventorySoftware\InventorySoftware\Form1.cs 34 27 InventorySoftware
-
Jack Frost about 10 yearsthanks for your reply but there is no tool in my VS2008 with name CrystalReportViewer but the ReportViewer alone is
-
Jack Frost about 10 yearsthere are alot of crystal report reference which one should i add?
-
Jack Frost about 10 yearsi've added all the reference with crystal report but still the same error :(
-
Jack Frost about 10 years
-
Jack Frost about 10 yearsthe error is " Error 1 'Microsoft.Reporting.WinForms.ReportViewer' does not contain a definition for 'ReportSource' and no extension method 'ReportSource' accepting a first argument of type 'Microsoft.Reporting.WinForms.ReportViewer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ahsan\Desktop\PROJECT INVENTORY SOFTWARE\InventorySoftware\InventorySoftware\Form1.cs 42 27 InventorySoftware "
-
Jack Frost about 10 yearsnot working out for me :(, i though you will not believe me thats why i created a video for you , the link of video is : screencast.com/t/Ed4XGzFAn
-
Jack Frost about 10 yearsit's still not comming ::(
-
Jack Frost about 10 yearsi've installed VS2010 but stil same problem is arising , my rest of software is working absolutely fine in VS2010 but i'm not able to see CrystalReportViewer there too :/
-
Jack Frost about 10 yearscan you please come on team sometime and can check what's the problem here , please if you can
-
Jack Frost about 10 yearsgive your ans a vote because at least you tried to help me out at your best mate, thanks for your feedback. :)
-
Jack Frost almost 10 yearsyup bro it was on Client Profile and finally i figured it out :) m happy :)