Visual Studio reporting

As I was in need to build reports in one of my applications, the most obvious choice was CrystalReports. It came with Visual Studio and also when you search on Google, most of the results you get when searching for reports for C# will be about Crystal Reports. Hmm, ok, I’ll use that I thought. There are many tutorials available on the internet, so I just used a couple to build my report.

After setting up and populating the DataSet for my report, time came to actually design the report. And here I lost my nerves – my report should have had a table or results, a simple table with a couple of columns and many rows. After opening the ToolBox for Crystal Reports, I though “ok now, where’s the table control?”. There was none. The workaround I used was this:

In the report header, I’ve put as many textboxes as there are columns. Aligning them to form a table header was a pain. I’ve put a border on every textbox and aligned them by their position manually using properties (yes, I calculated their X values manually). I did the same in the details region, where I’ve put the data fields and also had to align them like the header fields. After much struggle, the table was done. But. When I was viewing the report, there were gaps between the borders, so the table looked like a collection of cells scaterred around… I’ve spent a few hours ligning them. BUT. Time came when I had to add a new column to the table… and that means realigning all the columns by manually calculating and writing their coordinates one by one again… And it is a pain.

Another disappointment was deploying the application. Crystal Reports require additional redistributable to be installed and it doesn’t come with .NET framework, so obviously, the reports didn’t run on PCs which had only the .NET framework. A workaround for this is copying Crystal Reports dependency libraries locally, but that is like 5 or 6 additional DLLs. That was the end of my patience!

Luckily, I found a better solution: Microsoft Report Viewer.

You can add a report to your project by adding a “Report” item (not Crystal Report). The designer is much more better than the Crystal Reports one and it also has a table control to create tables in reports so much easier:

Reports are viewed using the ReportViewer control. That solved the table problem, but deployment problems still persisted. Luckily, there are just three file that you should include with your app: Microsoft.ReportViewer.Common.dll, Microsoft.ReportViewer.WinForms.dll, Microsoft.ReportViewer.ProcessingObjectModel.dll, first two being included in the project’s reference list when you add a report. As for the last file, you should get it from your computer’s Global Assembly Cache (GAC), on my computer it was in “c:\windows\assembly\gac_msil\microsoft.reportviewer.processingobjectmodel\”. Copy the file to your application’s directory and you’re ready to deploy!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s