[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


FastReports how to generate a master-detail report in code

Posted on 2011-10-17
Medium Priority
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
  • 2
  • 2
LVL 101

Expert Comment

ID: 36983297
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 101

Accepted Solution

mlmcc earned 2000 total points
ID: 36983316
The users manual for FastReports has an excellent example

Starts in section 2.22, page 48


Author Comment

ID: 37005951
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

ID: 37005955
Thanks. Problem solved.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

873 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