Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

C# Crystal Reports

Posted on 2016-07-27
15
92 Views
Last Modified: 2016-08-01
I've used Crystal Reports with .NET numerous times.  Usually the report is predefined.  However, I have a different requirement now.

I'm using Infragistics Ultragrid to display data.  With this control the user can move columns around and change the sort.  The user can also add grouping with this control by dragging a column to a grouping area.  I have to admit it is a nice feature.

However, the issue is that the requirement is once the user is done moving columns, clicking on the column to sort however they want, possibly adding a grouping they want to print the result with Crystal Reports.

Can this be done dynamically?

Thanks
0
Comment
Question by:CipherIS
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 41731500
You can prepare your dataset in the application, use it for the grid and and then use it as also as a datasource in Crystal report. Here is an article explaining how to develop the report and how to set the datasource:
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

Crystal reports have the ability to sort data dynamically too. If the only requirement is to sort the data you can do this directly in the report. If you want also to filter the data then you need to use the grid and the report. If you change the order of the columns in the grid or add/remove columns, group data etc .  this is not going to be transferred to the Crystal report. The report and the grid will use the same datasources but will have separate layouts.
0
 
LVL 1

Author Comment

by:CipherIS
ID: 41731517
Yes, I use a dataset. I usually use an XSD and pass the dataset to the report.

The solution I'm looking for is:

1.  Report at this time will contain 3 fields with no grouping.
2.  Report at this time will contain 4 fields with one grouping.
3.  Report at this time will contain 4 fields with one grouping.
Etc.

Each an any scenario, when the user clicks on the Print Preview button to display the report accurately.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41731609
wouldn't it be easier to just use the print feature of the grid?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:CipherIS
ID: 41731718
Is that possible?  

I also need to add a logo, Page # of #, DateTime.  Which is why I was using Crystal Reports.
0
 
LVL 18

Expert Comment

by:vasto
ID: 41731719
You can create different reports or subreports and run the right one based on the user action. However, very soon you will be in trouble because the users will start asking for new options. It is just not a good idea to use fixed structure as Crystal reports as a preview of dynamic , which is the table. As Eric said, just use the grid preview
0
 
LVL 1

Author Comment

by:CipherIS
ID: 41731723
So, a dynamic report is NOT possible?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41731798
nothing is impossible but in the case you want the user to control everything (column order, sort order, grouping, ...), CR is surely not the way to go.

maybe creating a HTML output from your grid would be a nice workaround! have a look at http://emoreau.com/Entries/Articles/2009/04/Using-LINQ-and-XML-Literals-to-transform-a-DataTable-into-a-HTML-table.aspx
0
 
LVL 1

Author Comment

by:CipherIS
ID: 41731808
If grouping is removed and user can only change column order and sort order?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41731834
it would be easier but then you will need to deal with column width and formatting and ...

I told you, HTML is surely your best option
0
 
LVL 18

Expert Comment

by:vasto
ID: 41731839
Crystal is fixed layout, you can add some codding and based on parameters to hide/show fields so for example you can show Customer field as a first , second, third etc.. column . However this will be enormous amount of work for very small benefit. You can use preview from the grid, it will show the data in the same was as it was on the screen.
0
 
LVL 1

Author Comment

by:CipherIS
ID: 41731917
How can I show preview from the grid?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41731929
for questions about the Infragistics UltraGrid, your best source will surely be http://www.infragistics.com/community/forums/65.aspx
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 41734556
How many columns might you want?

Are they different types?

You could pass parameters into the report with the field names or some indicator of the field then use formulas to display the data in the correct order.  You can do they same for grouping

Example

If {?Param1} = 'Name' then
    {NameField}
Else if {?Param1} = 'Address' then
    {AddressField}
Else if {?PParam1} = 'Salary' then
    CStr({SalaryField},2)
Else  
     ''

Similarly for grouping.

Put the formulas on the report in the desired format.
mlmcc
0
 
LVL 1

Author Comment

by:CipherIS
ID: 41734784
@mlmcc - question

So, if I use the parameters - lets say I create 5 of them but only need 3 for one report what will happen with the other 2?  I don't want errors on the report.

Thanks
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 41735422
Depending on the version of Crystal, you could make them all optional.

Another solution would be to pass a "bad" value so the formula results in a blank being displayed.

mlmcc
1

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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