Hi,
I use VB.NET under visual studio 2012.
I have a form that contain a datagridview, a picture and a button print.
I created the cristal report viewer to print the content of datagridview and the picture, for that, I added a datatable in witch I added fields for the datagridview columns and a field for the Image ( the Image field type is bytes()).
The problem is that all datagridview fields are displayed but the image is not displayed.
What I have tried:
When I click on the button Print, the datagridview content is shown in the Cristal Report Viewer but the image is not shown ( I already drag the Image field in the datatable to the cristal report viewer as I did with the other fields ).
I tried another method, which is to create a pivcture in the Cristal Report View >> Right Clic >> Format Object >> Picture >> X2 >> double clic on the image field in the datatable . Also with this method I got error " a blob field can not be used in a formula".
This is the code of the button PRINT :
Dim dt As New DataTable
With dt
.Columns.Add("code")
.Columns.Add("productnom")
.Columns.Add("category")
.Columns.Add("supplier")
.Columns.Add("qte")
.Columns.Add("Image", GetType(Byte()))
End With
pathUrl = Application.StartupPath & "\logo.png"
Dim img As Image = Image.FromFile(pathUrl)
Dim dr As DataRow = dt.NewRow()
dr("Image") = imageToByteArray(img)
dt.Rows.Add(dr)
For Each dgr As DataGridViewRow In Me.Datagridview1.Rows
dt.Rows.Add(dgr.Cells(0).Value, dgr.Cells(1).Value, dgr.Cells(2).Value, dgr.Cells(3).Value, dgr.Cells(4).Value)
Next
Dim reportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
reportDocument = New CrystalReport1
reportDocument.SetDataSource(dt)
FormPrint.CrystalReportViewer1.ReportSource = reportDocument
FormPrint.ShowDialog()
FormPrint.Dispose()
And the code of the function imageToByteArray is :
Public Function imageToByteArray(imageIn As System.Drawing.Image) As Byte()
Dim ms As New MemoryStream()
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Return ms.ToArray()
End Function
Plz, if someone could help me . Thanks