Recently some customers asked me how to use reportviewer 2010 in their visual studio 2008 project. ReportViewer 2010 fully supports both Visual Studio 2008 and Visual Studio 2010. The problem is that in Visual Studio 2008, you cannot directly use it in design time. This is a helpful hint, so I decided to dig it out. Really it works very well but need your efforts on extracting the DLLs from GAC and manually coding to create the reportviewer control. Here are my steps to show you how to make it work.

1. Download the ReportViewer 2010 Redistributable package from http://www.microsoft.com/downloads/details.aspx?FamilyID=a941c6b2-64dd-4d03-9ca7-4017a0d164fd&displaylang=en.

2. Install it on your computer, then the Microsoft.ReportViewer.WinForm.dll will be registered in GAC, however you could not directly reference this assembly from GAC in Visual Studio 2008. Referencing the assembly file is needed however the dll is not installed in other place. So the next step is how to extract the assembly file from the GAC.

3. John's blog showed some ways to extract assemblies from GAC. I used Windows Command Prompt to extract the Microsoft.ReportViewer.Winform.dll and Microsoft.ReportViewer. Common.dll out to my project's bin folder. You can first use the "cd" command to redirect the folder to " C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms", then use the "dir" command to check which folder is for ReportViewer 10.0 and run "cd" again to redirect to that folder, then run copy command like "copy Microsoft.ReportViewer.Winform.dll D:\Projects\MyTestReport\Bin\Microsoft.ReportViewer.Winform.dll" to copy the file to your project's bin folder. As well you can copy the Microsoft.ReportViewer. Common.dll file.

4. Then in Visual Studio 2008, right click the Reference folder, click "Add Reference...", switch to the Browse tab and add the references to these two assemblies. You can also add the ReportViewer control to the ToolBox via Choose Items by selecting the assembly Microsoft.ReportViewer.Winform.dll in the bin folder, but you will find that the control does not have real UI appearance. It just shows as a component but it is good since you can set properties via the property window.

5. Refer to those auto-generated code for the ReportViewer 2008 control in your project, manually add the code for your Reportviewer 2010 control to your Windows Form application accordingly.

6. For example, you have a form named Form1, modify the InitializeComponent function in Form1.Designer.cs as follows.

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();

            this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
            adventureWorksDW2008DataSet = new AdventureWorksDW2008DataSet();
            V_GETSALESTableAdapter = new WFMix.AdventureWorksDW2008DataSetTableAdapters.v_getSalesTableAdapter();

            this.SuspendLayout();
            //
            // reportViewer1
            //
            this.reportViewer1.LocalReport.ReportEmbeddedResource = "WFMix.Report1.rdlc";
            //this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
            this.reportViewer1.Location = new System.Drawing.Point(13, 13);
            this.reportViewer1.Name = "reportViewer1";
            this.reportViewer1.Size = new System.Drawing.Size(532, 352);
            this.reportViewer1.TabIndex = 0;

            Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource();
            rds.Name = "AdventureWorksDW2008DataSet_v_getSales";
            rds.Value = adventureWorksDW2008DataSet.v_getSales;
            this.reportViewer1.LocalReport.DataSources.Add(rds);

            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(708, 417);
            this.Controls.Add(this.reportViewer1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion

        private Microsoft.Reporting.WinForms.ReportViewer reportViewer1;
        private AdventureWorksDW2008DataSet adventureWorksDW2008DataSet = null;
        private AdventureWorksDW2008DataSetTableAdapters.v_getSalesTableAdapter V_GETSALESTableAdapter = null; 

7. In the Form_Load event, you can fill the data to refresh your report just like ReportViewer 2008. 

 

        private void Form1_Load(object sender, EventArgs e)
        {
            V_GETSALESTableAdapter.Fill(adventureWorksDW2008DataSet.v_getSales);
            this.reportViewer1.RefreshReport();
        }