Multicolumn Pictures in Crystal Reports

Hello guys, its been a while since a posted something on this blog. I was working on this project where an item can have as many pictures as possible, as part of the requirement , a report was to be generated to show the item information and its pictures ( in a multicolumn way).

Below are the steps to show pictures in crystal reports (Note that the the data type used is image and hence using datasets as the data source for the reports, the picture can easily be dragged onto the report)

1. To start, the picture is dragged to the detail section of the report as shown in the picture below

image

2. Then right click on the “detail section” tab and choose the “section expert” as shown in the picture below

image

3. In the dialog box that appear, make sure the “details” section is selected and on the right hand side, on the “common” tab make sure “Format with Multiple columns “ is checked. The move to the “Layout” tab, make the required changes and make sure in the “printing direction” section you select “across” and down.

image

4. You are now done, with the reports, run you program and something as shown in the picture below should be shown.

image

CREATING A CRYSTAL REPORT WITHOUT A DATASOURCE

If you want to generate crystal reports without using database tables, stored procedures, datasets but you want to generate reports with direct user inputs, for example printing receipts directly from user inputs, then here is your stop. It is all about using parameters. It is assumed you know how to generate reports with crystal reports.

Below is a simple procedure for you to do so.

To start with

Add a new crystal report document to your   project by choosing a blank report. Also create a form and add a crystalreportviewer to it. Design your report by creating the needed parameters that the report will accept from the user. For example as shown below

no datasource

Then add the method below to a click event. Don’t forget to do these imports

1.  Imports CrystalDecisions.CrystalReports.Engine

2. Imports CrystalDecisions.Shared

Private Sub printfees()

Dim rpd As New ReportDocument

‘loading the report from a specified location

rpd.Load(Application.StartupPath & "\reports\rptPaymentReceipt.rpt")

‘assigning values to your report parameters

rpd.SetParameterValue("prog", Me.txtProgram.Text)

rpd.SetParameterValue("sname", Me.txtName.Text.Replace("–", "").Trim)

rpd.SetParameterValue("acadyear", "Year: " & Me.lblYear.Text & " Sem:  " & Me.lblSemester.Text)

rpd.SetParameterValue("pdate", CDate(Me.dtpPaid.Value))

rpd.SetParameterValue("indexno", Me.txtIndexNo.Text)

rpd.SetParameterValue("ptype", Me.dspaytype.Rows(Me.cmbPaytype.SelectedIndex)(1).ToString)

‘frmReportsFace is a form with a crystalreportsviewer called crv1

Dim f As New frmReportsFace

f.crv1.ReportSource = rpd

‘below is a method to make your crystal reports independent on a ‘patrticular database server

SetDBLogonForReport(rpd)

f.Show()

End Sub

‘ a method that makes your crsystal reports independent on the database sever

Private Sub SetDBLogonForReport(ByVal myReportDocument As ReportDocument)

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()

‘dbase is a class to return certain information about databases,

myConnectionInfo.DatabaseName = dbase.getDataname

myConnectionInfo.UserID = dbase.getUName

myConnectionInfo.Password = dbase.getdbasePassword

myConnectionInfo.ServerName = dbase.getServerName

myConnectionInfo.IntegratedSecurity = dbase.getIntegratedSecurity

myConnectionInfo.AllowCustomConnection = True

Dim myTables As Tables = myReportDocument.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables

Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo

myTableLogonInfo.ConnectionInfo = myConnectionInfo

myTable.ApplyLogOnInfo(myTableLogonInfo)

Next

End Sub