Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in formatting the field object

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
0
0
DE
I have the following code,


Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Imports System.Data.OleDb

Public Class Form1
Dim cryrpt As New ReportDocument
Dim fs As FileStream
Dim br As BinaryReader
Dim dt As New DataTable
Dim rptobj As New CrystalReport1
Dim drow As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cryrpt.Load("E:\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")
Dim Connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\bbs_Excel\BBS.accdb")
Dim strSQL As String = "Select shape_code,bend_shape,A From data"
Dim DA As New OleDbDataAdapter(strSQL, Connection)
Dim DS As New DataSet

DA.Fill(DS, "data")


Dim rows As Integer = DS.Tables(0).Rows.Count
dt.Columns.Add("shape_code", System.Type.GetType("System.Int32"))
dt.Columns.Add("bend_shape", System.Type.GetType("System.Byte[]"))
dt.Columns.Add("A", System.Type.GetType("System.Int32"))
For i = 0 To rows - 1
Try
drow = dt.NewRow
If File.Exists(DS.Tables(0).Rows(i)(1)) Then
fs = New FileStream(DS.Tables(0).Rows(i)(1), FileMode.Open)
End If
br = New BinaryReader(fs)
Dim imgbyte(fs.Length) As Byte
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
drow(0) = DS.Tables(0).Rows(i)(0)
drow(1) = imgbyte
drow(2) = DS.Tables(0).Rows(i)(2)
dt.Rows.Add(drow)
br.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try


If dt.Rows(i)(0) = "0" Then
CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject).ObjectFormat.EnableSuppress = False
With CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject)
.Left = 0 * 1440
.Top = 0.14 * 1440
.Width = 0.16 * 1440
.Height = 0.25 * 1440
End With
Else
End If
Next

rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj
End Sub
End Class



Problem is the field object is not getting formatted. It is getting displayed as it is on the report.
 
sorry the code is,

Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Imports System.Data.OleDb

Public Class Form1
Dim cryrpt As New ReportDocument
Dim fs As FileStream
Dim br As BinaryReader
Dim dt As New DataTable
Dim rptobj As New CrystalReport1
Dim drow As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cryrpt.Load("E:\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")
Dim Connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\bbs_Excel\BBS.accdb")
Dim strSQL As String = "Select shape_code,bend_shape,A From data"
Dim DA As New OleDbDataAdapter(strSQL, Connection)
Dim DS As New DataSet

DA.Fill(DS, "data")


Dim rows As Integer = DS.Tables(0).Rows.Count
dt.Columns.Add("shape_code", System.Type.GetType("System.Int32"))
dt.Columns.Add("bend_shape", System.Type.GetType("System.Byte[]"))
dt.Columns.Add("A", System.Type.GetType("System.Int32"))
For i = 0 To rows - 1
Try
drow = dt.NewRow
If File.Exists(DS.Tables(0).Rows(i)(1)) Then
fs = New FileStream(DS.Tables(0).Rows(i)(1), FileMode.Open)
End If
br = New BinaryReader(fs)
Dim imgbyte(fs.Length) As Byte
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
drow(0) = DS.Tables(0).Rows(i)(0)
drow(1) = imgbyte
drow(2) = DS.Tables(0).Rows(i)(2)
dt.Rows.Add(drow)
br.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try


If dt.Rows(i)(0) = "0" Then
CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject).ObjectFormat.EnableSuppress = False
With CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject)
.Left = 0 * 1440
.Top = 0.14 * 1440
.Width = 0.16 * 1440
.Height = 0.25 * 1440
End With
ElseIf dt.Rows(i)(0) = "1" Then
CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject).ObjectFormat.EnableSuppress = False
With CType(cryrpt.ReportDefinition.ReportObjects("A1"), FieldObject)
.Left = 5 * 1440
.Top = 0.14 * 1440
.Width = 0.16 * 1440
.Height = 0.25 * 1440
End With

End If
Next

rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj
End Sub
End Class
 
Right-click on the field and let Crystal do the work. It can do a great deal and you don't need to do your own code.

There are also default options for fields on File > Options for Crystal 11.5, similar for other versions.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
I have such a requirement that i should do it from the code itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top