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

Creating pictureBox programmatically.

8 Answers 603 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ANDREI
Top achievements
Rank 1
ANDREI asked on 16 Apr 2014, 11:24 AM
Hello.

I have an "ImageModel" class List in a data source item. Every "ImageModel" instance contains byte array "Image" field. I need to create and add pictureBox to the panel for every  "Image" field. I try to do it in the panel's ItemDataBinding event handler:

 private void pnlImg_ItemDataBinding(object sender, EventArgs e)
        {
            var panel =  sender as Telerik.Reporting.Processing.Panel;
         
            var imageList = panel.DataObject["ImageList"] as ICollection<ImageModel>;
         
            var pictureBox = new Telerik.Reporting.PictureBox();

            for (int i = 1; i <= imageList.Count; i+=1)
            {
                pictureBox.MimeType = "image/jpeg";
                pictureBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(1.8D), Telerik.Reporting.Drawing.Unit.Cm(1.3D));
                pictureBox.Sizing = Telerik.Reporting.Drawing.ImageSizeMode.ScaleProportional;
                pictureBox.Visible = true;
                pictureBox.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(i%4==0 ? 0 : 1.8D*i), Telerik.Reporting.Drawing.Unit.Cm(1.3D*(i/4)));
                using (var ms = new MemoryStream(imageList.ElementAt(i-1).Image))
                {
                    pictureBox.Value = Image.FromStream(ms);
                }
                pnlImg.Items.Add( pictureBox );
            }
        }

In the result I get the empty panel. I tried to use Telerik.Reporting.Processing.PictureBox() instead Telerik.Reporting.PictureBox(), but there is no ability to create an instance of a Telerik.Reporting.Processing.PictureBox. Is there any ability to create pictureBox programmatically and add it to a Telerik.Reporting.Panel? I'm using Telerik Reporting Q1 2014 Trial Version.

Thanks!

8 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 18 Apr 2014, 09:20 AM
Hi Andrei,

Instead of adding PictureBoxes programmatically our recommendation is to use nested data items (List) and bind the nested data item with Binding:
Property path  Expression
 DataSource  =Fields.ImageList

Then you can add PictureBox to the List Panel and according to the ImageList structure set the PictureBox.Value to the following expression:
=Fields.Item
or
=Fields.Image

Regards,
Peter
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ANDREI
Top achievements
Rank 1
answered on 18 Apr 2014, 01:40 PM
Hi Peter,

In this case I have another problem, I cannot arrange images. I need to display for example 5 images in one line  and go to another line in order not to display all images in one horizontal or vertical column. But I could not find a way to do it. All images a displayed in one column. I thought that using panel's ItemDataBinding event handler I can specify location of every image. Can you tell me, how to  display several images in one line and go to another line?

Thanks!
0
Nasko
Telerik team
answered on 23 Apr 2014, 10:36 AM
Hello Andrei,

If you need to display the images in multiple columns/rows you can use the Crosstab item instead of the List item. It can display aggregated data summaries, grouped in rows and columns. The number of rows and columns for groups is determined by the number of unique values for each row and column groups.
For more information, please refer to the Grouping Data and Understanding CrossTab areas help articles.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Madhu
Top achievements
Rank 1
answered on 21 Nov 2014, 09:59 AM
Dear Sir,


Can You send me some code for adding picturebox programatically.

thanks
vilas
0
Nasko
Telerik team
answered on 25 Nov 2014, 09:11 AM
Hello Vilas,

You can generate the sample code using the Visual Studio Report Designer.
Create a new report and add a PictureBox item in the Visual Studio Report Designer and use the automatically generated code in the .Designer.cs file as a template for dynamic PictureBox generation. You may also find useful the Reporting API Reference.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 03 Jan 2017, 09:11 AM

Hello, 

Is there any sample code for this? I am trying to do something similar but not entirely sure how to wire everything up. 

Thanks!

Chris

0
Stef
Telerik team
answered on 05 Jan 2017, 10:31 AM
Hi Chris,

Based on your support history, you have a list of image objects that you need to display in a report.

We can suggest you to use a List item, then place a PictureBox item in it. Set the List.DataSource to the list of image objects  via ObjectDataSource, and the PictureBox.Value to an expression like Fields.Item (the Expression Editor will let you see he correct name of the image field).


If you need further help, please elaborate on the data you will use, how it is retrieved and how it should be visualized in a report.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Chris
Top achievements
Rank 1
answered on 05 Jan 2017, 11:19 AM

Hi Stef, 

Your approach is close to the one I used however I used an expression to set the list control datasource and picturebox value. I had a simple List<Image> that I needed to bind to and this post: 

http://www.telerik.com/forums/binding-collection-of-simple-types-e-g-list-lt-string-gt

by Monsignor was the missing piece for me.  Hopefully this can help someone else as well. 

Chris

Tags
General Discussions
Asked by
ANDREI
Top achievements
Rank 1
Answers by
Peter
Telerik team
ANDREI
Top achievements
Rank 1
Nasko
Telerik team
Madhu
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Stef
Telerik team
Share this question
or