Search code examples
c#listviewimagelist

c# - listview does not shows different icons for all item/images?


I am trying to make an image gallery in C#.
I am having a problem in viewing thumbnails of images in a ListView.
One image shows for all images in image list.

This is a ScreenShot:

 Screen Shot

And this is the code:

foreach (string path in filePaths)
{
    int i = 0;
    filename.Add(Path.GetFileName(path));
    images.Images.Add(i.ToString(),Image.FromFile(path));
    ImageView.Items.Add(Path.GetFileNameWithoutExtension(path),i);
    richTextBox1.Text += path + Environment.NewLine;
    i++;
}

Solution

  • Each list view item has an ImageIndex property. By default its a 0, so it would show the first image.

    While its unclear what your data types are, I think this is what you want.

    int i = 0;
    
    foreach (string path in filePaths)
        {
            filename.Add(Path.GetFileName(path));
            images.Images.Add(i.ToString(),Image.FromFile(path));
           ImageView.Items.Add(Path.GetFileNameWithoutExtension(path),i);
    
            richTextBox1.Text += path + Environment.NewLine;
            i++;
        }