Print Page | Close Window

Preview Crystal Report on Windows Form in C#

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=8610
Printed Date: 04 May 2024 at 11:19pm


Topic: Preview Crystal Report on Windows Form in C#
Posted By: koncuk
Subject: Preview Crystal Report on Windows Form in C#
Date Posted: 10 Dec 2009 at 4:49am
There is a button on a windows form called Print the Report. It should show a report as a new form on the screen if I use the button.

I have created a new form and added crystalviewer but I don’t have any code. I have defined the reportsource.

Which code should I write in click option of the button.

Thanks for your help.



Replies:
Posted By: hilfy
Date Posted: 10 Dec 2009 at 10:36am

If all you need to do is open the form to show the report, you just need to .show() the new form.

If you want to make the form generic so that it can show different reports or so that you can set parameters or if you need to use a DataSet from your application, here's what I do:
 
1.  Override the constructor for the new form to add parameters for the report name or type, DataSet, and/or report parameters.
 
2.  In the overridden constructor, set the various properties for the requested report.
 
I have sample code for something similar to this on my website - http://www.geocities.com/geekgurl7/sample_code.html - www.geocities.com/geekgurl7/sample_code.html .  Look for the BOEUserAudit application in about the middle of the page.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: koncuk
Date Posted: 11 Dec 2009 at 2:39am
thank you so much your helping,

I wanted to show the report as a form.
I like your opinions so I have finded your web side downloaded the link but it doesn't work.

And also I want to do this;
The report will show on screen and there will be a button on it. It should send to printer the report when I click the button .



Posted By: hilfy
Date Posted: 11 Dec 2009 at 7:16am
The Crystal Viewer component has a print button, so you shouldn't have to specifically program one.
 
If you're trying to compile my code, it needs the full BusinessObjects Enterprise SDK, which you probably don't have.  However, you can use the code in BOEAuditRptViewer.cs as an example of how to set up your viewer form, modifying it for your own needs.  The code to call the form is in the RunReport method in BOEUserAuditForm.cs.
 
Basically, you have to create the viewer form and then .Show() it.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window