derekantrican
derekantrican

Reputation: 2283

Adding a group of images to ListView

I have a ListView and a List<Image> (there are 3 images in the list). I'm trying to add all the images to the ListView and currently this is what I have:

foreach (Image image in ListOfImages)
{
    PictureBox pictureBox = new PictureBox();
    pictureBox.BackColor = Color.Gray;
    pictureBox.Width = 200;
    pictureBox.Height = 200;
    pictureBox.Image = image;
    pictureBox.SizeMode = PictureBoxSizeMode.Zoom;

    listView1.Controls.Add(pictureBox);
}

And this is what it looks like in the end:

image

That image is the first one in my list. The other two aren't visible. Is there a reason why the others aren't showing up?

Upvotes: 0

Views: 223

Answers (2)

derekantrican
derekantrican

Reputation: 2283

Ok, I've found that the correct answer for what I want to do is to not use a ListView but to instead use a FlowLayoutPanel. The code above will work exactly the same way, except instead of listView1 it should be flowLayoutPanel1 (or whatever the name of the FlowLayoutPanel is)

Upvotes: 0

aks
aks

Reputation: 342

I think microsoft has a better solution to offer - ImageList. Why can't you use the ImageList?

I can help you one that First create an Imagelist control from Toolbox. Set your istview's imagelist. e.g. listView1.LargeImageList = imageList1;

foreach (Image image in ListOfImages)
{
    imageList1.Images.Add(image);
}

Add list Items to your list control and mention the respective image index.

 listView1.Items.Add(key, text, imageindex);

Hope this helps!

Upvotes: 1

Related Questions