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

Add Images to a ListView - IconView

5 Answers 347 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Alfonsina
Top achievements
Rank 1
Alfonsina asked on 13 Dec 2012, 09:10 AM
Hallo Telerik Team,

I would like to know how I add a list of images to a ListView as Icon View. The path images are in a List<string> and they are into:
C://Documents/Pic/.
How can I do that? The images paths are saved in a dataTable in a database.

Thank you very much.

Best regards,

Alfonsina Mello


5 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 14 Dec 2012, 01:38 PM
Hi Alfonsina,

Thank you for contacting us.

You need to iterate through the paths and create items with that image:
foreach (string fileName in files) // files is List<string>
{
    ListViewDataItem item = new ListViewDataItem();
    item.Image = Image.FromFile(fileName);
    this.radListView1.Items.Add(item);
}

I hope this helps. If you have any other questions, feel free to write back.

Regards,
Ivan Todorov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Alfonsina
Top achievements
Rank 1
answered on 14 Dec 2012, 01:43 PM
Hallo Telerik Team,

Thank you very much. It has worked. Now I have another question. I have my images in the RadListView and when
I click one image, it shows no selection. how can I do that. I would like to select the images.

Thank you very much!

Best regards,

Alfonsina
0
Ivan Todorov
Telerik team
answered on 18 Dec 2012, 02:33 PM
Hello Alfonsina,

You should not lose the selection highlight when your items have images assigned unless the images are overlaying the background. Please make sure your images have a transparent background. If you continue experiencing difficulties, please open a new support ticket and attach a project which demonstrates the issue. This will let me investigate it and provide you with further support.

Do not hesitate to contact us if you need further assistance.

Greetings,
Ivan Todorov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Oscar
Top achievements
Rank 2
answered on 21 Feb 2014, 03:40 PM
Hi, this works, but how can I strech the Image ? there is no a strech true, or item.Image.Strech property, I use aligment, but it doesn't work in 2013 q3 tha I am testing, in 2013 q1, it works,
here is my code:

            ListViewDataItem item = new ListViewDataItem(e.fileName);
            item.Text = e.fileName;
            item.ImageAlignment = ContentAlignment.TopCenter;
            item.TextImageRelation = TextImageRelation.TextBeforeImage;

            
            item.TextAlignment = ContentAlignment.BottomCenter;

            Image img = Image.FromFile(e.fileName);
            
                          
            radListViewMedia.Items.Add(item);


0
Stefan
Telerik team
answered on 24 Feb 2014, 07:39 AM
Hello Oscar,

Thank you for writing. 

To make an image stretch, you should use the VisualItemFormatting event and set the VisualItem's ImageLayout property:
void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
    e.VisualItem.ImageLayout = ImageLayout.Stretch;
}

I hope this helps. 

Regards,
Stefan
Telerik
Tags
ListView
Asked by
Alfonsina
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Alfonsina
Top achievements
Rank 1
Oscar
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or