How to flip between a text response and a databound PictureBox when image is null?

1 Answer 50 Views
Binding DataSource SQL PictureBox Report Viewer - WinForms Table
Damien
Top achievements
Rank 1
Damien asked on 31 Oct 2022, 01:36 AM

I have a report that has been around for years and it only was SQL database-fed text information, one of which was an indicator result. 

I have since updated the application to include the ability to take photo of the indicator and save the binary data into the database, as well as any text response.

Now I need to update my report to show an image if there is one, or show the text response if there is no image - all in the same cell/column.

Firstly, do I just grab and send the binary data for the picturebox in the report's table, and how do I show either the image (if not null) or the text in the same cell on each row?

thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 01 Nov 2022, 02:12 PM

Hello Damien,

I have already replied to the Support ticket you raised on the same issue. For the benefit of our community, I will add the sample report definition and the steps for achieving it also here.

  • Place a Panel in the cell where you would like to have either an image or a text.
  • In the Panel, put a PictureBox item with a Value corresponding to the data field with the image data. The Image data may be byte[], Image instance, base64 string, etc. as specified in the article describing the item.
  • Over the PictureBox place a TextBox item with a Value corresponding to the text to be displayed if there is no image.
  • Use Bindings or Conditional Formatting to show/hide the PictureBox/TextBox conditionally, based on the image. For example, you may use the following Expression to set the Visible property of the TextBox, and the opposite for the PictureBox:
= (Fields.Image = "") Or (Fields.Image Is Null)

The part that checks whether the image is an empty string may not be needed if your image is a byte[]. In my case, I use URLs and I had to add the test for an empty string to have the report running properly. Here is also the Expression for the PictureBox from the sample. You may also skip the empty string check:

= (Fields.Image <> "") And (Fields.Image Is Not Null)

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
Binding DataSource SQL PictureBox Report Viewer - WinForms Table
Asked by
Damien
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or