Click here to Skip to main content
Click here to Skip to main content

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 7 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.shivasoft.in/blog
Follow on   Twitter   LinkedIn

Comments and Discussions

 
GeneralMy vote of 1 PinmemberSafetyOtter28-Apr-14 12:13 
QuestionLinks don't work in your tutorial PinmemberSPHTS28-May-13 0:53 
GeneralRecommendation Pinmembernasalien8-Feb-13 22:17 
Questionusing object datasource Pinmemberkarthik2004k30-Dec-12 0:58 
GeneralGood article. Pinmemberigorz13-May-12 7:25 
GeneralMy vote of 1 PinmemberRizviHasan15-Apr-12 22:48 
GeneralReason for my vote of 1 In-appropriate title Pinmemberunknowndentified1011125-Aug-11 18:51 
GeneralReason for my vote of 3 This code very useful for all who wa... Pinmemberk.shekhar111-Feb-11 0:44 
QuestionThere were no instruction on how to view a Crystal Report Document for WPF Pinmemberunknowndentified1011125-Aug-11 18:51 
Generalthanks PinmemberARIA 518-May-11 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.141022.2 | Last Updated 1 Jul 2010
Article Copyright 2010 by Jitendra Zaa
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid