Winforms ReportViewer not showing

2019-09-11 05:33发布

问题:

I am using Visual Studio Express 2012, I am trying to invoke my deployed reports using winforms, this is what i did.

  1. I created a new c# winforms application
  2. I went to the toolbox to look for the ReportViewer control(but it wasnt there)
    2.1 So i added it manually by right clicking Toolbox > Choose Items > then i selected the report viewer
  3. After that i dragged and dropped it on the form(but it goes straight to the bottom tray and doesn't give me any options)

I have seen many questions that address the same issue but with no solution.

回答1:

The problem was Microsoft.ReportViewer.WinForms version 10, I am not sure why, but it was doing the same thing on my colleague's computer.

Here is what I did:

  1. I download and installed Microsoft.ReportViewer.WinForms version 11.0.0.0
  2. I went to the toolbox and right clicked > Choose Items
  3. From there I deselected Microsoft.ReportViewer.WinForms version 10 and selected version 11.
  4. I then went back to my solution to drag and drop the report viewer to my form, it worked


回答2:

I tried the accepted answer but it didn't work to me.

So, another solution could be:

In your Designer.cs file, you have to add this line (manually):

this.Controls.Add(this.reportViewer1);

This is my example in a form called "FrmPreviewRpt1":

//
// FrmPreviewRpt1
// 
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(725, 305);
this.Controls.Add(this.reportViewer1); // This is the new line.
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "FrmPreviewRpt1";
this.Text = "FrmPreviewRpt1";
this.ResumeLayout(false);

Here is a screenshot of the result:

The bad news with this approach is that you have to change the size (and possibly other visible attributes) in the Designer.cs file manually.