Results 1 to 5 of 5

Thread: [RESOLVED] Inserting dynamic image in crystal report

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Resolved [RESOLVED] Inserting dynamic image in crystal report

    Hi to all,

    I use Vb.net 2008 version and crystal Reports 2008 V12

    I had create a OLE.Object in my report and i need to put, dynamicattly, a picture into this OLE.Object...the OLE.Obect name is Picture6

    I had create this instruction into my code:
    Code:
    Dim pic = CType(rpt.ReportDefinition.ReportObjects("Path_imagem_carro_piloto"), PictureObject)
            pic.ObjectFormat.EnableSuppress = True
    but i have an error that is "Index out of limits", and sincerelly i don't know the way to resolve this.

    This is the code that i use to call the report and put a few thinks on it:

    Code:
      Dim Pathreport As String = ""
    
            Pathreport = String.Concat(My.Application.Info.DirectoryPath & "\listagem_pilotos_prova.rpt")
    
    
            Dim rpt As New ReportDocument
            Dim pval As New ParameterValues()
            Dim disVal As New ParameterDiscreteValue()
    
    
    
            rpt.Load(Pathreport)
    
            rpt.SetDataSource(ds.Tables("Table"))
    
    
            Dim pic = CType(rpt.ReportDefinition.ReportObjects("Path_imagem_carro_piloto"), PictureObject)
            pic.ObjectFormat.EnableSuppress = True
    
    
    
            'Right on Parameters Fields
            disVal.Value = classificacao_piloto
            pval.Add(disVal)
            rpt.DataDefinition.ParameterFields("classificacao").ApplyCurrentValues(pval)
    
    
            disVal.Value = total_pontos_piloto
            pval.Add(disVal)
            rpt.DataDefinition.ParameterFields("pontuacao").ApplyCurrentValues(pval)
    
           
          
            'View the Report
            CRViewer1.ReportSource = rpt

    Any help please?

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Inserting dynamic image in crystal report

    Hey.
    All example's I've seen suggest to add the image field to the database.
    I don't like that. If I have time tomorrow I would try to pass a picture from a path, not the SQL server.After that...It's vacation time!!
    For now, here's an example (it's asp but you get the idea)

    https://www.c-sharpcorner.com/Upload...-sql-database/
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: Inserting dynamic image in crystal report

    Hi,

    I Appreciate your help....Your example, in fact, is to add an image to the database, and it's not my problem.
    My problem is just put an image into CR

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Inserting dynamic image in crystal report

    OK.
    I did it. Must have been one of the trickiest things ever. Mixed Crystal info here an there on the internet but not an exact solution.
    Rather than Crystal smarties developers create a simple pictureobject1 = newpicture we need to go around Africa, Australia,Asia and back in Europe
    It is simple but I had to take exact steps else it wouldn't work.
    So what you do is this:
    1)Add an Image to the report (crystalreport) , on Section 1 report header (for now, so we can simulate a working image), name it "Picture1"
    2)Create a new parameter field.Just give it a name (I named it "0" as you will see on the code)
    3)Go to your image. Right click -- format object --(tab) picture -- check Use Original Uri, Click on the formula workshop button at the bottom right of the picture tab
    4)On formula workshop, go to Formatting Formulas -- Report Header -- Picture1 -- Graphic Location. You will see a tab "Report Fields" with a value of "0". Double click to add to the formula.Save and exit

    Name:  Clipboard01.jpg
Views: 10866
Size:  26.4 KB

    5)If all is OK, you will see a parameter field named 0 on the field explorer tab.
    So now the image you have added to the report has a parameter field that you need to change to show a new image in place of the old one.
    That will be done like this:

    Code:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.ReportAppServer.CrystalReportDataRowView
    
    ''''''Add to button click or something
    
    Dim cr As New CrystalReport1
    cr.SetParameterValue("0", "C:\newimage.jpg") ''' -- Note , "0" is the parameter field name we created before and second param of SetParameterValue is the location + new image  you set to replace the old one
    
    ' For crystal viewer not to ask you to specify the parameter in a pop up box, you need to do:
    Dim paramFields As New CrystalDecisions.Shared.ParameterFields()
    Dim paramField As New CrystalDecisions.Shared.ParameterField()
    Dim discreteVal As New CrystalDecisions.Shared.ParameterDiscreteValue()
    
    paramField.ParameterFieldName = "0"  ' again the parameter field name we created
    discreteVal.Value = "C:\newimage.jpg"   ' once more the new image name and location
    paramField.CurrentValues.Add(discreteVal)
    paramFields.Add(paramField)
    
    CrystalReportViewer1.ParameterFieldInfo = paramFields
    
    CrystalReportViewer1.Refresh()
    CrystalReportViewer1.ReportSource = cr
    This is an initial test, you can poke a little and bring it to your needs, but I'm leaving for vacation, so not much time for now.
    Last edited by sapator; Aug 10th, 2018 at 08:21 AM. Reason: Monster of Rock, impossible to stop.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: Inserting dynamic image in crystal report

    Hi,

    Fantastic sapator...the problem as resolved

    Best regards and many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width