0

I'm trying to download thumbnails and show them in a listview. What am I doing wrong ?

ListView loads but it doesn't show any thumbnails.

 using (var webClient = new WebClient())
        {
            foreach (var thumb in imgFiles.Item1)
            {
                byte[] data = webClient.DownloadData(thumb);
                using (MemoryStream imageData = new MemoryStream(data))
                {
                    Image img = Image.FromStream(imageData);
                    thumbList.Images.Add(img);
                }
            }
        }

 for (var i = 0; i < thumbList.Images.Count; i++)
        {
            ListViewItem lvi = new ListViewItem();
            lvi.ImageIndex = i;
            lvi.SubItems.Add("test");
            lvi.SubItems.Add("test1");

            lvi.Text = i.ToString();

            listViewLinks.Items.Add(lvi);
        }
        listViewLinks.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

ListView loads without images

ragouel
  • 179
  • 4
  • 15
  • Can you see the images if you just put them in the window, outside of the grid? – Marisa Nov 09 '17 at 15:32
  • Did you set the ``ImageList``? Have a look at the very bottom of https://msdn.microsoft.com/en-us/library/system.windows.forms.listview(v=vs.110).aspx – Rand Random Nov 09 '17 at 15:33
  • What is `thumbList`? You have to use proper view and fill proper image list in given `ListView`. See [this answer](https://stackoverflow.com/a/5255732/1997232). – Sinatr Nov 09 '17 at 15:37
  • thumbList is ImageList, @RandRandom :Yes. – ragouel Nov 09 '17 at 15:47

1 Answers1

0

You can try with the below code.

listView1.SmallImageList = thumblist;
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add("A");
lvi.SubItems.Add("B");
lvi.SubItems.Add("C");
lvi.ImageIndex = 2; // this will display YourImageList.Images[2] in the first column
listView1.Items.Add(lvi);

Are you able to getting ImageList.

Anjali
  • 1,680
  • 4
  • 26
  • 48