FastReports how to generate a master-detail report in code

Posted on 2011-10-17
Last Modified: 2012-05-12
Fast Reports Inc. home siteRulesHelpSearchMembersCalendar  
 Search this forum only? More Search Options [X]My Assistant
 Loading. Please Wait...
   Site Message (Message will auto close in 2 seconds)
Logged in as: BatteryPack ( Log Out )
My Controls · View New Posts · My Assistant · My Friends · 0 New Messages

 Fast Reports forum > Fast Reports Products > FastReport 4.0

 Master-Detail using Code, How do you create a Master-Detail in code  Options  Track this topic  Email this topic  Print this topic  Download this topic  Subscribe to this forum Display Modes Switch to: Outline  Standard  Switch to: Linear+

   View Member Profile  Add as Friend  Send Message  Find Member's Topics  Find Member's Posts   Today, 03:33 AM Post #1  


Group: Members
Posts: 3
Joined: 14-October 11
Member No.: 54120

 Hi all.

I am trying out the demo software, and am most impressed with FastReport.
However, I have run into a fundamental problem for which there seems to be no documentation whatsoever.

I need to generate master-detail reports in code.
My example is a small school consisting of 3 teachers, each having 3 pupils.

All data comes from simple xml, and SQL is not used anywhere.

<?xml version="1.0" encoding="utf-8"?>

I generate a schema which produces a typed dataset.

I proceed as follows.

public partial class Form1 : Form
public school School;
public school.teacherDataTable Teachers;
public school.pupilDataTable Pupils;

public Form1()
School = new school();
Teachers = new school.teacherDataTable();
Pupils = new school.pupilDataTable();


I then try to generate a FasReport as follows:

private void btnLoad_Click(object sender, EventArgs e)
Report report = new Report();
report.RegisterData(School, "school");
report.RegisterData(School.Tables["teacher"], "teacher");
report.RegisterData("pupil", "relationteacher_pupils");
report.GetDataSource("teacher").Enabled = true;

ReportPage page1 = new ReportPage();
page1.Name = "Page1";
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = Units.Millimeters * 15f;

TextObject SchoolTitleText = new TextObject();
SchoolTitleText.Name = "SchoolTitle";
SchoolTitleText.Bounds = new RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
SchoolTitleText.Text = "NorthDale School";
SchoolTitleText.HorzAlign = HorzAlign.Left;
SchoolTitleText.Font = new Font("Tahoma", 14, FontStyle.Bold);

GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 1;
group1.Condition = "[teacher.TeacherName]";

group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Millimeters * 5;

DataBand databand1 = new DataBand();
databand1.Name = "Data1";
databand1.Height = Units.Centimeters * 0.5f;
databand1.DataSource = report.GetDataSource("teacher");
group1.Data = databand1;

TextObject TeacherText = new TextObject();
TeacherText.Name = "TeacherText";
TeacherText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
TeacherText.Text = "[teacher.TeacherName]";
TeacherText.Font = new Font("Tahoma", 11, FontStyle.Bold);


DataBand Databand2 = new DataBand();
Databand2.Name = "Data2";
Databand2.Height = Units.Centimeters * 0.5f;
Databand2.DataSource = report.GetDataSource("pupil");

TextObject PupilText = new TextObject();
PupilText.Name = "PupilText";
PupilText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
PupilText.Text = "[pupil.Name]";
PupilText.Font = new Font("Tahoma", 10, FontStyle.Regular);


The report correctly lists the 3 teacters, but each teacher has all 9 pupils intead of 3.

I have hunted high and low for any documentation on how to create the master-detail relationships using code, but amazingly, there does not seem to be any.
The basic PDF deals only with a simple list, and the downloadable Net documentation is devoid of any guidance at all.

I would be most obliged if someone can assist me with this very fundamental task, so that I can go ahead and buy the software.
Question by:PruneBottle
    LVL 100

    Expert Comment

    You have to create a relationship between the tables.

    I showed you how to do it in Crystal (which requires no code, just creating the report in the GUI).

    When I opened the XML in Crystal it showed 3 tables
    Teacher, Pupils, Pupil

    Teacher                             Pupils                            Pupil
    ClassId                              ClassId                         PupilId
    TeacherName                    PupilId                           PupilName

    Somewhere you have to link the tables.  Crystal uses the link editor and generates SQL to implement the data reading and table linking.  I don't know FastReports so I can't say how to do it.

    LVL 100

    Accepted Solution

    The users manual for FastReports has an excellent example

    Starts in section 2.22, page 48


    Author Comment

    Hello mlmcc.
    I was not aware that this pdf existed as they have another one they call "programmers guide".

    However, when I got hold of the one you mentioned, everything became much clearer, and I now see that I can do without code.

    This is a fine piece of software.

    Thanks for your help.

    Author Closing Comment

    Thanks. Problem solved.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    A short article about a problem I had getting the GPS LocationListener working.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now