Solved

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

Posted on 2009-05-07
14
628 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Offline Apllication 5 72
Error in script 11 58
Question! 4 36
C# Object Reference is Required for the non-static field, method, or property 10 35
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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