Add Images to a ListView - IconView

6 posts, 0 answers
  1. Alfonsina
    Alfonsina avatar
    13 posts
    Member since:
    May 2012

    Posted 13 Dec 2012 Link to this post

    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


  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 14 Dec 2012 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alfonsina
    Alfonsina avatar
    13 posts
    Member since:
    May 2012

    Posted 14 Dec 2012 Link to this post

    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
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 18 Dec 2012 Link to this post

    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.
  6. Oscar
    Oscar avatar
    3 posts
    Member since:
    Jun 2011

    Posted 21 Feb 2014 in reply to Ivan Todorov Link to this post

    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);


  7. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 24 Feb 2014 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready