Load data from service within a report

Stimulsoft Reports.WPF discussion
Post Reply
ChristianMyksvoll
Posts: 18
Joined: Thu Sep 22, 2011 8:42 am
Location: Norway

Load data from service within a report

Post by ChristianMyksvoll »

Hi.
I need to load data from within a report after collecting some report criteria in a report form. So far I have solved this the following way:

Program code:

Code: Select all

var reportService = new ReportService();

var report = new StiReport();
report.Load("report.mrt");
report.RegData("ReportService", reportService);

report.DesignWithWpf();
Button click event for a form within the report that I use to collect data:

Code: Select all

IReportService reportService = this.Dictionary.DataSources["ReportService") as IReportService;

IList personList = reportService.FindPersons("Christian");

foreach(Person person in personList)
{
	MessageBox.Show(person.Name);
}
This is working as expected, showing the names in messageboxes. How do I make use of the personList in the report? I want to use personList as a datasource for a DataBand, but I have not found a way to do this yet.
Attachments
1335.TestProject-VS2010.zip
(19.56 KiB) Downloaded 252 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Load data from service within a report

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

report.RegBusinessObject(reportService);
Thank you.
ChristianMyksvoll
Posts: 18
Joined: Thu Sep 22, 2011 8:42 am
Location: Norway

Load data from service within a report

Post by ChristianMyksvoll »

Hi.
I am not sure you understood my question correctly.

My problem is not how to access the reportService object. I already manage to call the method reportService.FindPersons("Christian") from within the report code.

I have a correctly filled IList of Person objects (I have verified this by showing each person's name in a message box).

What I need now is to make use of this dynamically loaded list and display each person's properties in a StiDataBand in the report. Is this possible?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Load data from service within a report

Post by Alex K. »

Hello,

Sorry, perhaps we did not understand your question correctly. Just to make it clear, do you want to set a business object for the data band from your application code or report code? If possible, please send a sample project for analysis.

Thank you.
ChristianMyksvoll
Posts: 18
Joined: Thu Sep 22, 2011 8:42 am
Location: Norway

Load data from service within a report

Post by ChristianMyksvoll »

I want to set a business object from the report code.

Here is what I am trying to do:
1) User opens the report from my application
2) A form in the report is displayed to the user where he types a search string and clicks an Ok-button
3) In the Ok-button click event, I call the method FindPersons in the reportService object
4) The FindPersons method returns an IList of Person objects
5) I want to display data from this list in a StiDataBand
6) The generated report is displayed to the user


I will set up a test project as soon as possible and post it in this thread.
ChristianMyksvoll
Posts: 18
Joined: Thu Sep 22, 2011 8:42 am
Location: Norway

Load data from service within a report

Post by ChristianMyksvoll »

I have now attached a test project to the first post in this thread.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Load data from service within a report

Post by Alex K. »

Hello,

Please check the modified report in attachment.

Thank you.
Attachments
1338.Report_modified.mrt
(13.72 KiB) Downloaded 622 times
ChristianMyksvoll
Posts: 18
Joined: Thu Sep 22, 2011 8:42 am
Location: Norway

Load data from service within a report

Post by ChristianMyksvoll »

That works just the way I want it :biggrin:

For everyone else that may be interested in the solution, here is the final source code for the button click event in the report:

Code: Select all

IReportService reportService = this.Dictionary.DataSources["MetaData"].GetData("ReportService") as IReportService;
IList personList = reportService.FindPersons("Flintstone");

//this.Dictionary.DataSources.Remove(this.Dictionary.DataSources["PersonList"]);

this.RegData("PersonList", personList);
PersonList is an already registered datasource that contains no actual data, but I need it to be able to connect a databand to it.

When replacing a datasource with new content, removing the old one is obviously not necessary (the commented line). It actually gave me nothing but trouble. As usual, Keep It Simple Stupid :shame:
Andrew
Posts: 4108
Joined: Fri Jun 09, 2006 3:58 am

Load data from service within a report

Post by Andrew »

Hello,

Thank you for sharing your experience with other developers.

Post Reply