Solved

How do I generate an ActiveReport dynamically in C# using an object

Posted on 2009-05-07
14
630 Views
Last Modified: 2012-05-06
How do I generate an ActiveReport for a C# project dynamically using a object from the main project. I have an object referencing subobjects and I want to pass the whole class structure as my datasource to an ActiveReport from my C#.Net application.
The report will print something like this:
SECTION
----CATEGORY
----------SUBCATEGORY
-----------------QUESTION_TEXT, QUESTION_ANSWER

Open in new window

0
Comment
Question by:eddiecon
  • 8
  • 6
14 Comments
 
LVL 8

Expert Comment

by:mac-will
ID: 24327716
Create a new 'object' datasource from the datasources panel
0
 

Author Comment

by:eddiecon
ID: 24327759
Thanks for responding so quickly. Can you be a bit more specific. Do you perhaps know of a walkthrough showing how to do this. My object is already created and I just want to pass my populated object to the report. Do my object need to adhere to a certain standard so that the report can understand it?
0
 
LVL 8

Expert Comment

by:mac-will
ID: 24327818
Go to the Data Menu -> Add New Datasource...

Select "Object" as the type and select your class as the object.

I don't know of any examples off hand but you could probably search for them on google
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:eddiecon
ID: 24327865
Thank you. Let me try your suggestion. I google'd for an answer but nothing really comes back that looks like what I want to do, but then I must say that I haven't worked yet through all the google'd pages that came back. So many pages, so little time. Let me see what I can do. Thanks once again.
0
 

Author Comment

by:eddiecon
ID: 24328167
I did what you suggested and it created an entry for my 'Object' datasource under my Reports assembly inside the Properties subfolder of the 'Reports' assembly. It created a subfolder under that called 'DataSources' and placed the entry inside that folder. I got exited because all that should be left to do is to open the 'Report Explorer' of my .Net IDE and drag the fields of the 'OBJECT' onto the report but there are no fields, just the layout of my report appears in the 'Report Explorer'.
I went down to the properties window for each field and GroupHeader on my report to see if the 'fields' of my OBJECT will appear in the dropdown of the 'DataField' property but there is nothing.
Am I doing something silly?
0
 
LVL 8

Expert Comment

by:mac-will
ID: 24338719
Datasource Objects only show object properties.  What you need to do is wrap your fields in a property.

(right-click on the fields and select encapsulate field)

Refresh and you should see all the public properties of the object.
0
 

Author Comment

by:eddiecon
ID: 24343074
Thank you very much mac-will. Will let you know if your suggestion sorted out my problem. Very much appreciated.
 
0
 

Author Comment

by:eddiecon
ID: 24350161
I still did not sort this out. Tell me, when you say "...wrap your fields in a property...", do you just refer to the creation of the getters and setters for each field in my class/object? Well I went through the encapsulation suggestion an all it did was creating another set of getters and setters in my class for each attribute/field in my class.

When you say "refresh" do you mean I should refresh the "Report Explorer" window so the fields should appear from where I can drag and drop them on my report?
0
 
LVL 8

Expert Comment

by:mac-will
ID: 24357075
Yes, Encapsualte == getters and setters (In the C# format of a class property)

Refresh the datasource so you can see the newly added PUBLIC properties.
0
 
LVL 8

Assisted Solution

by:mac-will
mac-will earned 20 total points
ID: 24357113
Here is a quick screenshot showing an object property as a datasource field.
demo.jpg
0
 

Author Comment

by:eddiecon
ID: 24361793
Ok. That was my understanding also.
The only difference between your image and my program is the following:
1. You don't have 'public' infront of your class declaration.
2. My object and it's fields are not appearing in the 'Data Sources' window.
I will keep trying. Must have done something wrong somewhere.
 
0
 

Author Comment

by:eddiecon
ID: 24366217
I got it working with a "flat structured" object. What I mean by that is that I have a small object with only two fields in it and no IList's of objects going from that object(embedded objects). I also discovered that after you created your object, that it is wrong to assume that it will be available to the DataSource add wizard. You have to rebuild your solution first and only then the object will be visible and available to be added as part of the DataSource you want to create. I know that perhaps to you all out there this might be general knowledge but I have overseen the mentioned.
I am now going to create a "big flat structured object" from my existing object which contains embeded objects. It will produce a "result set" as follows which I will then pass to the report as my DataSource:

SECTION_01, CATEGORY_01, SUBCATEGORY_01, QUESTION_01
SECTION_01, CATEGORY_01, SUBCATEGORY_01, QUESTION_02
SECTION_01, CATEGORY_01, SUBCATEGORY_02, QUESTION_01
SECTION_01, CATEGORY_01, SUBCATEGORY_02, QUESTION_02
SECTION_01, CATEGORY_02, SUBCATEGORY_01, QUESTION_01
SECTION_01, CATEGORY_02, SUBCATEGORY_01, QUESTION_02
SECTION_01, CATEGORY_02, SUBCATEGORY_02, QUESTION_01
SECTION_01, CATEGORY_02, SUBCATEGORY_02, QUESTION_02
SECTION_02, CATEGORY_01, SUBCATEGORY_01, QUESTION_01
SECTION_02, CATEGORY_01, SUBCATEGORY_01, QUESTION_02
SECTION_02, CATEGORY_01, SUBCATEGORY_02, QUESTION_01
SECTION_02, CATEGORY_01, SUBCATEGORY_02, QUESTION_02
SECTION_02, CATEGORY_02, SUBCATEGORY_01, QUESTION_01
SECTION_02, CATEGORY_02, SUBCATEGORY_01, QUESTION_02
SECTION_02, CATEGORY_02, SUBCATEGORY_02, QUESTION_01
SECTION_02, CATEGORY_02, SUBCATEGORY_02, QUESTION_02
etc., etc.
So my report should then print something like this: (--- replace spaces just for this message)
SECTION_01, CATEGORY_01, SUBCATEGORY_01, QUESTION_01
------------------------------------------------------------------------QUESTION_02
------------------------------------------, SUBCATEGORY_02, QUESTION_01
------------------------------------------------------------------------QUESTION_02
-------------------, CATEGORY_02, SUBCATEGORY_01, QUESTION_01
------------------------------------------------------------------------QUESTION_02
-----------------------------------------, SUBCATEGORY_02, QUESTION_01
------------------------------------------------------------------------QUESTION_02
SECTION_02, CATEGORY_01, SUBCATEGORY_01, QUESTION_01
------------------------------------------------------------------------QUESTION_02
-----------------------------------------, SUBCATEGORY_02, QUESTION_01
------------------------------------------------------------------------QUESTION_02
-------------------, CATEGORY_02, SUBCATEGORY_01, QUESTION_01
------------------------------------------------------------------------QUESTION_02
-----------------------------------------, SUBCATEGORY_02, QUESTION_01
------------------------------------------------------------------------QUESTION_02
etc., etc.

Will let you know as soon as I get it to work.
0
 

Accepted Solution

by:
eddiecon earned 0 total points
ID: 24367368
It works!!! Thank you mac-will for your patience.
I think I should slam together a walkthrough or at least a small example of what I have done. It might help others.
Thanks once again.
 
0
 
LVL 8

Expert Comment

by:mac-will
ID: 24386557
no problem - good luck
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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