Solved

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

Posted on 2009-05-07
14
623 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
How to avoid saving tif files a 2nd time using VS2015 and C#? 1 26
Not showing page correctly 3 29
Angular JS Route 3 44
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
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 …

948 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

22 Experts available now in Live!

Get 1:1 Help Now