Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change an image in a Crystal Report at runtime

I'm using the Crystal Reports included with VisualStudio 2005. I would like to change the image that is displayed on the report at runtime ideally by building a path to the image file and then have that image displayed on the report.

Has anyone been able to accomplish this with this version of Crystal Reports?

like image 952
Keith Avatar asked Sep 24 '08 16:09

Keith


2 Answers

At work we do this by pushing the image(s) into the report as fields of a datatable. It's not pretty, but it gets the job done. Of course, this solution requires that you push data into the reports via a DataSet. I've always felt this was a hack at best. I really wish that image parameters were a possibility with CR.

Edit: It's worth noting, if you are binding your crystal report to plain old objects you want to expose a byte[] property for the report to treat that as an image.

like image 58
Josh Bush Avatar answered Oct 04 '22 01:10

Josh Bush


The current version of Crystal Reports (for Visual Studio 2012+) that I use with Visual Studio 2015 supports this function. Follow the following steps:

  1. Insert a picture into your report. This will serve as your placeholder.'
  2. Right click your picture and choose Format Object Right Click Image
  3. Select the Picture tab and the press the formula button Picture Tab
  4. A formula window will open. Enter a formula that will find your pictures as links.

    if({@isDonor}="1") then "http://www.ny.org/images/aaf/picture1.jpg" else "http://www.ny.org/images/aaf/picture2.jpg" Formula Editor And you're done!

like image 27
Glenn Gordon Avatar answered Oct 04 '22 00:10

Glenn Gordon