This is a migrated thread and some comments may be shown as answers.

Change PictureBox at Runtime

5 Answers 433 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 02 Jul 2012, 09:20 AM
Hi there

I have a trdx file that contains the definition of my report, when I show it with the reportviewer, I would like to change the signature image to the user that is logged in.

at the moment I have this
System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(templatePath, settings))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
 
 
    Telerik.Reporting.Report certificateReport = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
    uxCertificateViewer.ReportSource = certificateReport;
    uxCertificateViewer.RefreshReport();
}

Im not sure how to access and set the picturebox image before I assign it to the reportViewer. There is no DB data being binded to this report.

Thank you

5 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 03 Jul 2012, 08:01 AM
You can try with this method:
report.Items.Find(Type type, bool recursive);
and when you find the picture simply change the image data. 
0
Justin
Top achievements
Rank 1
answered on 18 Mar 2013, 09:28 PM
I have this same issue with a TRDX report but my report is bound to a datasource. The datasource contains a URL to my picture. How do i set the picture to my file?

I saw this code in another form-post:
private void pictureBox1_ItemDataBinding(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.PictureBox pic = (Telerik.Reporting.Processing.PictureBox)sender;
            string img = HttpContext.Current.Server.MapPath("img.jpg");
            Image myImg = Image.FromFile(img);
            pic.Image = myImg;
        }

the trdx files don't have code-behind so I don't know where to put it! I also use VB.NET so can you give me a solution in VB.net?

-Justin
0
Jako
Top achievements
Rank 1
answered on 19 Mar 2013, 06:27 AM
Hi Justin

What I ended up doing was count the position of the picture box on the actual TRDX in the designer and then do something like this:

Telerik.Reporting.PictureBox companyLogo = (certificateReport.Items[0].Items[2].Items[1] as Telerik.Reporting.PictureBox);
 
            if (File.Exists(logoPath))
                companyLogo .Value = logoPath;

You should be able to convert this easily to VB.Net
0
Squall
Top achievements
Rank 1
answered on 20 Mar 2013, 03:41 PM
Hi Justin,

Have you tried to set the PictureBox.Value property with expression. Something like this: =Fields.MyPictureURL

SN
0
Rory
Top achievements
Rank 1
answered on 11 Jan 2016, 07:16 PM

this is how I did it,

 pbLogo.ItemDataBinding += pbLogo_ItemDataBinding;

void pbLogo_ItemDataBinding(object sender, EventArgs e)
{
            pbLogo.Value = "=GetLogo(ReportItem)";
}

 

public static Image GetLogo(Telerik.Reporting.Processing.ReportItem reportItem)
 {
            string logo = Utilities.GetLogo(FilePathToImage);
            Image myImg = Image.FromFile(logo);
            return myImg;
 }

Tags
General Discussions
Asked by
Jako
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Justin
Top achievements
Rank 1
Jako
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Rory
Top achievements
Rank 1
Share this question
or