Solved

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

Posted on 2009-05-07
14
618 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
Comment Utility
Create a new 'object' datasource from the datasources panel
0
 

Author Comment

by:eddiecon
Comment Utility
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
Comment Utility
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
 

Author Comment

by:eddiecon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much mac-will. Will let you know if your suggestion sorted out my problem. Very much appreciated.
 
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:eddiecon
Comment Utility
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
Comment Utility
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
Comment Utility
Here is a quick screenshot showing an object property as a datasource field.
demo.jpg
0
 

Author Comment

by:eddiecon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no problem - good luck
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

9 Experts available now in Live!

Get 1:1 Help Now