Click here to Skip to main content
12,622,032 members (32,411 online)
Click here to Skip to main content
Add your own
alternative version

Stats

64.1K views
16 bookmarked
Posted

Crystal Report in WPF

, 1 Jul 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Download source codeIntroductionThis article will describe that how to add crystal report in WPF application step by step. BackgroundThere is no report viewer tool directly available in WPF. So how to use the Reportviewer control of windows form to WPF will be described in this...
Download source code


Introduction

This article will describe how to add Crystal report in WPF application step by step.

Background

There is no report viewer tool directly available in WPF. So how to use the Reportviewer control of Windows Form to WPF will be described in this article.

Steps to create the application

Create a WPF application.


After that, create the xsd to display data in Crystal report. (Here I am using XSD instead of database to make the tutorial easy for beginners.


One screen will come to configure the XSD. The final structure of the XSD should look like:


As shown, we can change the datatype of the columns.

Let's add the dummy data to display in the report.

billXsd = new Bill();
billXsd.Tables[0].Rows.Add(1,"Minal","Windows XP Software",2,15000);
billXsd.Tables[0].Rows.Add(1, "Minal", "Avast Antivirus", 2, 5000);
billXsd.Tables[0].Rows.Add(1, "Minal", "Laptop", 2, 100000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "Dell Laptop", 1, 70000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "IPhone", 1, 45000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "Camera", 1, 25000);
billXsd.Tables[0].Rows.Add(3, "Manoranjan", "IP Phone", 10, 100000);
billXsd.Tables[0].Rows.Add(3, "Manoranjan", "Apple Laptop", 3, 200000); 

Now, add the references of the crystal report in your application.


Now create a crystal report named BillDemo.


After that, select the report type as standard and after that, select XSD created earlier.


After selecting XSD, select the column names to display on the report.


If required, you can select the Group by field also as shown in the below picture:


Create Total field (formula field) using editor


One can format the look of any field like font color, size, etc. by selecting "Format object option".


The complete function to show the report:

billXsd = new Bill();
billXsd.Tables[0].Rows.Add(1,"Minal","Windows XP Software",2,15000);
billXsd.Tables[0].Rows.Add(1, "Minal", "Avast Antivirus", 2, 5000);
billXsd.Tables[0].Rows.Add(1, "Minal", "Laptop", 2, 100000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "Dell Laptop", 1, 70000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "IPhone", 1, 45000);
billXsd.Tables[0].Rows.Add(2, "Santosh", "Camera", 1, 25000);
billXsd.Tables[0].Rows.Add(3, "Manoranjan", "IP Phone", 10, 100000);
billXsd.Tables[0].Rows.Add(3, "Manoranjan", "Apple Laptop", 3, 200000);
BillDemo report = new BillDemo();
report.SetDataSource(billXsd);
CrystalReportViewer rptViewer = new CrystalReportViewer();
WindowsFormsHost host = new WindowsFormsHost();
rptViewer.ReportSource = report;
host.Child = rptViewer;
reportGrid.Children.Add(host); //Add report viewer in WPF Grid
Output:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jitendra Zaa
Software Developer (Senior) Cognizant Technology Solutions
India India
Having more than 9 years of experience in Programming and web application development.

Writing technical blog articles, learning new Programming languages , frameworks and sharing knowledge with others is one of my hobby. The more I learn, more I understood that how little I know and that drives me to dig into technology and languages to explore.

From last few years now, working on Salesforce platform and providing customer solutions using force.com as an Architect and Technical Lead Role. I have worked on many area of Salesforce like force.com, Heroku, PHP Toolkit, Partner Webservices, Metadata and Enterprise webservices, Tooling API, Customer Portal, Partner Portal, Community, Salesforce1 etc...

Blog:http://www.jitendrazaa.com/blog

You may also be interested in...

Pro

Comments and Discussions

 
BugFix the images Pin
MayurPadhiyar4-Jan-16 23:53
memberMayurPadhiyar4-Jan-16 23:53 
GeneralMy vote of 1 Pin
SafetyOtter28-Apr-14 13:13
memberSafetyOtter28-Apr-14 13:13 
QuestionLinks don't work in your tutorial Pin
SPHTS28-May-13 1:53
memberSPHTS28-May-13 1:53 
GeneralRecommendation Pin
nasalien8-Feb-13 23:17
membernasalien8-Feb-13 23:17 
Questionusing object datasource Pin
karthik2004k30-Dec-12 1:58
memberkarthik2004k30-Dec-12 1:58 
GeneralGood article. Pin
igorz13-May-12 8:25
memberigorz13-May-12 8:25 
GeneralMy vote of 1 Pin
RizviHasan15-Apr-12 23:48
memberRizviHasan15-Apr-12 23:48 
GeneralReason for my vote of 1 In-appropriate title Pin
unknowndentified1011125-Aug-11 19:51
memberunknowndentified1011125-Aug-11 19:51 
GeneralReason for my vote of 3 This code very useful for all who wa... Pin
k.shekhar111-Feb-11 1:44
memberk.shekhar111-Feb-11 1:44 
QuestionThere were no instruction on how to view a Crystal Report Document for WPF Pin
unknowndentified1011125-Aug-11 19:51
memberunknowndentified1011125-Aug-11 19:51 
Generalthanks Pin
ARIA 518-May-11 3:45
memberARIA 518-May-11 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 1 Jul 2010
Article Copyright 2010 by Jitendra Zaa
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid