Setting value of picturebox based on field value

6 posts, 0 answers
  1. Malcolm
    Malcolm avatar
    15 posts
    Member since:
    Dec 2011

    Posted 22 May 2012 Link to this post

    Hello all. I am trying to learn how to set the value of a picturebox based on the value of a particular field. My situation is that I have a report that combines employees from various companies and so I need to set the correct company logo for each employee. I am very new to telerik and am not so well versed in c# so I am hoping someone who speaks my language (vb.net) will point me in the right direction. So far I have discovered that I have no idea how to reference a field value in my code nor do I know how to use that value, if I knew how to get it, to then populate my picturebox. Thanks to you all for any and all help in this matter.

    Malcolm X
  2. Steve
    Admin
    Steve avatar
    10940 posts

    Posted 24 May 2012 Link to this post

    Hello Malcolm,

    You can set the value of a PictureBox directly from the Report Designer by using appropriate Expression.
    For more information refer to the Expressions as Values of Item Properties help article. Also check the PictureBox help article for supported ways to set an image.
    In addition if you’re using the designer in Visual Studio and have connected to a data source, you can simply drag the image field from the Data Explorer window onto your report. The designer is smart enough to know what kind of report item to associate with each field based on its data type.

    Greetings,
    Steve
    the Telerik team

    BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

  3. Malcolm
    Malcolm avatar
    15 posts
    Member since:
    Dec 2011

    Posted 24 May 2012 Link to this post

    Steve - thanks for the quick reply! I feel like you got me closer but something is still escaping me. I have made 2 different attempts at this and am still not getting it done.

    Here is attempt one:
    Private Sub PictureBox1_ItemDataBound(sender As Object, e As System.EventArgs) Handles PictureBox1.ItemDataBound
     
        PictureBox1.Value = "=IIf(Fields.LocationRecID = 10,My.Resources.ehtpt_logo, My.Resources.logo1)"
     
    End Sub

    I'm not sure I put that piece of code in the right spot but regardless it does not like my reference to "My.Resources"

    I also tried something similar in the Bindings area of the designer for the picture box and got the same results...it doesn't like my reference to "My.Resources".

    Am I just thinking wrong here with my attempt to use picture files in my resources area?

    Malcolm X
  4. Malcolm
    Malcolm avatar
    15 posts
    Member since:
    Dec 2011

    Posted 24 May 2012 Link to this post

    Steve - I think I am a little closer now. I created a function that got me results;

        Shared Function GetLogo(LocationID As Integer) As Image

            Dim EHTPTLogo As Image = My.Resources.ehtpt_logo
            Dim AccessLogo As Image = My.Resources.logo1

            If LocationID = 10 Then

                Return EHTPTLogo

            Else

                Return AccessLogo

            End If

        End Function

    I stuck a call to that function in the picturebox binding expression that looks like this;

    =GetLogo(Fields.LocationRecID)

    My problem now is that it does not fire every time. It seems to fire once at start grabs the correct logo for that first employee but then every other page/employee is stuck with the same logo.

    I feel like I am real close here but not sure what to do so that as you navigate from page to page the proper logo is shown.
  5. Steve
    Admin
    Steve avatar
    10940 posts

    Posted 28 May 2012 Link to this post

    Hi Malcolm,

    The user function would be invoked as many times as records in your datasource i.e. it would be evaluated for each new value of the Fields.LocationRecID, so what you report is really strange. If you're still having problems it would be best to provide a sample report that shows the problem.

    Kind regards,
    Steve
    the Telerik team

    BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

  6. Muhammad
    Muhammad avatar
    27 posts
    Member since:
    Oct 2017

    Posted 09 Feb 2018 in reply to Steve Link to this post

    Hi Steve,

    I'm running pretty much same problem right now. I am also trying to get the value of the picture box from field and the datatype of the field in Varbinary(Max). But I am getting an error of GDI+. Is this something to do with the datatype ?
    I had an image which was in PNG format and I uploaded it which then was saved in Varbinary field.
    Please help me out.

    Regards,
Back to Top