Home > front end >  Installing and using ReportViewer in Visual Studio 2022 Windows Forms
Installing and using ReportViewer in Visual Studio 2022 Windows Forms

Time:01-19

I have tied several times to install the report designer and report viewer into studio 2022. The install for the report designer worked fine. I can create wizard and do-it-yourself .rdlc reports.

I'm totally new to this. All of the online tutorials about using the report tools start with 'drag a report viewer into a form and start configuring it.'

Installing the report viewer to the toolbox is from the nuget package and then the dll from browsing the project folder for the dll. Unfortunately when I added the report viewer to the form from the toolbox, the report viewer drops below the form and will not let me configure it as in all the tutorials.

I have tried the report viewer 2010, version 11, version 12, and version 15 packages including the one that said it fixed a problem with the package not installing all the needed dlls.

According to the tutorials there should be a smart tag. This does not happen, and I cannot see any properties i can link to the report. I've tried linking the reportviewer to the rdlc by putting it into the localreport ReportEmbeddedResource property but nothing shows when you run the code.

Have I not set this up correctly, or is the tool not working?

CodePudding user response:

You need to install the followings:

  • enter image description here

    Note: If you forgot to build the project after creating Product class, the class doesn't appear in the list of classes for data source.

  • Open ToolBox > Drop an instance of Table on the report, hover the mouse over the first cell of the second row and click on DB Icon to bind it to Id column, and do the same on second cell of the second row to bind it to Name column. Then save the report:

    enter image description here

  • Open the form in design mode, and from ToolBox, drop an instance of Report Viewer on the form. You can find it on top or the toolbox under Microsoft Sql Server category.

    enter image description here

  • Click on the smart tag (the arrow), and choose Report:

    enter image description here

  • Click on the Choose Data Source, and in the window, choose Product. It will add a productBindingSource to your form:

    enter image description here

  • Double click on form and add the following code:

    private void Form1_Load(object sender, EventArgs e)
    {
        this.productBindingSource.DataSource = new List<Product>()
        {
            new Product(){ Id=1, Name= "Lorem" },
            new Product(){ Id=1, Name= "Ipsum" },
        };
        this.reportViewer1.RefreshReport();
    }
    
  • Run the project and see the result:

    enter image description here

  • Related