Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

CSharp Crystal Reports – sub reports



Create a Crystal Reports using three tables and select customer name, date, product and qty. It will explain in detail the previous section C# Crystal Reports from multiple tables.

Next step is to create a subreport inside the main report. Here we are showing the Product details in each row of the specified product in the main row.

After creating the main report, right-click on Crystal Reports designer window and select Insert-Subreport.

Then you will get the subreport object, drag the object in the designer window at the down part of the details tab, just below the fields in the Details tab. When you release the mouse you will get a dialogue box asking report name. Enter a report name, and click the Report Wizard button.

The wizard shows the table selection screen and selects the table. Here, in this case, we have to select the Product Table from the list and click next.

Next screen is showing the table, from there select the fields you want to show the data and click finish. Then you will get the subreport main screen again and select Link tab.

The link tab is making relation with your main Report and subreport. Here we are linking the product name from the main report to the subreport. For that select Product.Product_name from Available fields.

Accept the other settings as it is in the screen and click ok. Now you can see the subreport object in the screen if you want to re-arrange subreport design, double click on subreport object then you can design subreport.

Now the designing part is over and the next step is to call the Crystal Reports in C# and view it in Crystal Reports Viewer control.

Select the default form (Form1.cs) you created in C# and drag a button and a CrystalReportViewer control to your form.

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }
    }
}

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More