Creating a Crosstab Report in Visual Studio 2005 Using Crystal Reports
page 5 of 6
by Jayaram Krishnaswamy
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 97347/ 182

Generating the Report

In order to produce a report after creating a Garnet.rpt document, a Report Viewer control on a form is needed.  The preview of the Main Report shows how the report would display in its final form.  In order to display the report on a form in the windows application, you will need to add a form to the project and then drag and drop a CrystalReportViewer control on to the form as shown in Figure 25.  The Crystal ReportViewer occupies the whole form, as shown with several of the icons grayed out.  These will become active once the CrystalReportViewer is configured to show the report by establishing the relationship between these two objects in the IDE.

Configuring the CrystalReportViewer is facilitated by the .NET feature called the smart tasks, in this case the CrystalReportViewer Tasks.

CrystalReportViewerTasks shows the various tasks that need to be performed.  Obviously, the first choice would take you through the necessary steps of creating a New Crystal Report.  In this tutorial this has already been accomplished.  The second item, Choose a Crystal Report…, would help you in choosing an existing Crystal Report that can be viewed on this viewer.

Figure 25

 

When you access the CrystalReportViewer's properties window by right clicking it, you will be able to make changes to various items.  This includes the choice of choosing a CrystalReport from among the various reports that may exist (as shown in Figure 26) where the Diamond.Garnet report will be chosen.  You may also browse for other reports that may be residing in the machine as well.

Figure 26

 

When you make the above choice, the properties pages get the binding to the report created earlier.  In addition to adding the CrystalReport to the CrystalReportViewer you may make many other choices as well.  The key elements of the CrystalReportViewerTasks also appear at the bottom of the CrystalReportViewer properties.

Figure 27

 

By associating the Diamond.Garnet [ProjectName.ReportName] report source with the CrystalReportViewer1, the binding is automatically established as shown in the Code behind the CrossTab.Designer.vb a part of which is reproduced in Listing 2.

Listing 2

Private Sub InitializeComponent ()
        Me.CrystalReportViewer1 = New Crystal Decisions. _
        Windows.Forms.CrystalReportViewer
        Me.Garnet1 = New Diamond.Garnet
        Me.SuspendLayout ()
        'CrystalReportViewer1
        Me.CrystalReportViewer1.ActiveViewIndex = 0
        Me.CrystalReportViewer1.BorderStyle = System.Windows.Forms. _
        BorderStyle.FixedSingle
        Me.CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.CrystalReportViewer1.Location = New System.Drawing.Point (0, 0)
        Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
        Me.CrystalReportViewer1.ReportSource = Me.Garnet1
        Me.CrystalReportViewer1.Size = New System.Drawing.Size (419, 497)
        Me.CrystalReportViewer1.TabIndex = 0
        'Crosstab
        Me.AutoScaleDimensions = New System.Drawing.SizeF (6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size (419, 497)
        Me.Controls.Add (Me.CrystalReportViewer1)
        Me.Name = "Crosstab"
        Me.Text = "Crosstab"
        Me.ResumeLayout (False)
    End Sub

The report is now ready for prime time.  Just build the project and make sure that the Crosstab is the Startup form and run.  You should be able to see the report now hosted on the Crosstab form as shown in Figure 28.  You may also notice that the information has exceeded the limits of a page spread to a second page.  You may use the navigation buttons at the top to go to the next page and once in the next page to come back.  The various icons in the report menu are now active for printing, zooming, searching, etc.

Figure 28

 

 

All elements on the design area are configurable.  Figure 29 shows how the Row#1 Name object can be formatted by clicking the object which brings up a context sensitive menu from which you can accomplish your task.  This will bring up the Format Editor window as shown in Figure 30.  For example, by choosing the Graph1 object the title can be changed.

Figure 29

When you choose the Format Object in the drop-down, you will be invoking the Format Editor shown in Figure 30.  The editor comes with the defaults and, as shown in Figure 30, the row elements are centered.  This was changed to "Left" as shown in Figure 30.  Now when the report is open, the rows will be aligned to the left.

Figure 30

 

Similarly the font was changed from the default of "Arial" to "Garamond," as shown in Figure 31.

Figure 31

 

 

It is possible to modify the formatting of all objects from their default values using the design interface.  When you are sufficiently satisfied, you rebuild the projects and run to display the form.  This is the completed cross-tab report of the data from the Northwind database.

Figure 31

 

 


View Entire Article

User Comments

Title: Show chart of row in cross-tab   
Name: letamuns
Date: 2012-02-20 12:01:53 AM
Comment:
Hi! Thanks for your article. In case: I want to have a link of every row, when I click it, the crystalreportviewer show a chart for that row.
Title: how to print value   
Name: nithya
Date: 2011-10-08 2:58:28 AM
Comment:
how to print the values in between section4 and section5 in crystal report in asp.net
Title: Cross Tab Report   
Name: Bharti
Date: 2011-08-02 10:51:33 AM
Comment:
Hi!

Thanks for a helpful article. I have created a cross tab report and need to modify the order of records. I am sorting a field by specified order and have added another one to the sort field. At this point the records were all sorted correctly and easily. My report is not recognising this new data which I have added. I removed the sort and when I run the report the same sort is still in the report. What am I doing wrong?

Thank you.
Title: thanks   
Name: manisha
Date: 2011-06-06 5:45:03 AM
Comment:
excellent thanksssss
Title: CR   
Name: Engineer
Date: 2011-05-31 1:45:38 AM
Comment:
Thnx..helpful article
Title: Very Good   
Name: Very Good
Date: 2011-05-21 5:33:45 AM
Comment:
Thanks,
This article is very helpful.
Title: Cross tab   
Name: Reda Karim
Date: 2011-05-08 10:35:36 AM
Comment:
Thanks very much it was very helpful for me
Title: Cross tab   
Name: Gaja
Date: 2010-08-11 2:49:20 AM
Comment:
How to remove summarized field in cross tab option
Title: Crystal report cross tab   
Name: Suhail
Date: 2010-05-31 4:30:32 AM
Comment:
Hello Sir,I have the same problem in cross tab that is there is no sum in Summary field of cross tab can u pls help me how to include that
Title: Cross Tab   
Name: das
Date: 2010-04-22 7:06:56 AM
Comment:
Hi,
Is it possible to enable the "Can grow"(Fig 30) propery of a field?
If no,What is the solution?
Title: How to make a cross-tab reprt without summarizing any field?   
Name: Vicky
Date: 2010-02-26 1:31:37 AM
Comment:
Sir i've developed a Time Management System in which emplyees attendance is stored.
I've to make a cross tab report for this project, in which i've to mention Incoming Time, Outgoing etc.
But i dont have to summarize any field.
Please help me out in this regard.

Advance Thanx
Vicky
Title: CrossTab   
Name: ABJ
Date: 2009-10-03 2:13:58 AM
Comment:
Really Great.. 100 points to you.. :-)
Title: Cross Tab Crystal Report   
Name: Jayaram Krishnaswamy
Date: 2009-07-15 12:31:55 PM
Comment:
Hi Deepak,

If you would let me know how you are doing this with some more details I may be able to help you. I replied to your email instead of commenting here.

Cheers,

Jay
Title: crosstab crystal report   
Name: deepak
Date: 2009-06-03 1:23:35 AM
Comment:
sir i am not getting the sum function in the drop down list just below the summary filed in the cross tab .....

can u please help.....
i will be thankful..
regards
deepak

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-03-23 9:03:12 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search