Skip to Content
0
Former Member
Dec 01, 2011 at 10:33 PM

Formatting CR displayed on a Web Form

35 Views

VS 2008 - CR for VS 2008

I have a CR being displayed on a web form using a CrystalReportViewer control.

For some reason, the CrystalReportViewer messes up the format of the CR on the web from, although it prints fine with all it's original formatting.

I have the following code to format the CR on the web form. the ".EnableCanGrow = True" works but the ".HorizontalAlignment = Alignment.LeftAlign" does not. I don't understand why that is...

Protected Sub Print_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Print.Click

Dim crReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim CrystalReportViewer As CrystalDecisions.Web.CrystalReportViewer = New CrystalDecisions.Web.CrystalReportViewer

Dim JobType As String = DropDownType.SelectedValue

Dim Store As String = DropDownStore.SelectedValue

Dim Salesperson As String = DropDownSPname.SelectedValue

Dim CustomerName As String = DropDownCustomer.SelectedValue

crReport.Load(MapPath("JobReport.rpt"))

ConfigureCrystalReports(crReport)

crReport.SetDataSource(GetCustomData(JobType, Store, Salesperson, CustomerName))

Session("CrystalReportViewer.ReportSource") = crReport

Response.Redirect("JobReport.aspx")

End Sub

Private Sub ConfigureCrystalReports(ByVal myReport As ReportDocument)

Dim ReportType As String = ""

Dim ReportTypeCriteria As String = "CrystalDecisions.CrystalReports.Engine.FieldObject"

Dim idx As Int32

Dim fo As CrystalDecisions.CrystalReports.Engine.FieldObject = Nothing

For idx = 0 To myReport.ReportDefinition.ReportObjects.Count - 1

ReportType = myReport.ReportDefinition.ReportObjects(idx).GetType.ToString

If ReportType.Equals(ReportTypeCriteria) Then

fo = DirectCast(myReport.ReportDefinition.ReportObjects(idx), CrystalDecisions.CrystalReports.Engine.FieldObject)

With fo.ObjectFormat

.HorizontalAlignment = Alignment.LeftAlign

.EnableCanGrow = True

End With

End If

Next

End Sub