Open Crystal Report in Winform

12,015

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...".

enter image description here

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:

enter image description here

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:

enter image description here

Share:
12,015
Jack Frost
Author by

Jack Frost

Updated on June 04, 2022

Comments

  • Jack Frost
    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 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  34  27  InventorySoftware
    
  • Jack Frost
    Jack Frost about 10 years
    thanks for your reply but there is no tool in my VS2008 with name CrystalReportViewer but the ReportViewer alone is
  • Jack Frost
    Jack Frost about 10 years
    there are alot of crystal report reference which one should i add?
  • Jack Frost
    Jack Frost about 10 years
    i've added all the reference with crystal report but still the same error :(
  • Jack Frost
    Jack Frost about 10 years
  • Jack Frost
    Jack Frost about 10 years
    the 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
    Jack Frost about 10 years
    not 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
    Jack Frost about 10 years
    it's still not comming ::(
  • Jack Frost
    Jack Frost about 10 years
    i'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
    Jack Frost about 10 years
    can you please come on team sometime and can check what's the problem here , please if you can
  • Jack Frost
    Jack Frost about 10 years
    give your ans a vote because at least you tried to help me out at your best mate, thanks for your feedback. :)
  • Jack Frost
    Jack Frost almost 10 years
    yup bro it was on Client Profile and finally i figured it out :) m happy :)