2

I need to add more than two images for a list view item and I know that I can use two lists only: StateImageList and either Large or SmallImageLists by setting both ImageIndex and StateImageIndex. Is there a possibility to add more than two images on the same list view tem (same column).

Thank you!

Ștefan Blaga
  • 404
  • 1
  • 5
  • 22
  • You would have to ownerdraw the listview, I believe. – TaW Oct 17 '19 at 12:26
  • this might help https://stackoverflow.com/questions/15366294/listview-in-c-sharp-with-images – demoncrate Oct 21 '19 at 16:22
  • Do you want 2 images side by side? depending on the number of combinations you could programatically draw new images that show the combinations you need and make one big list? I answered a similar question (although it was how to do it in ObjectListView which is an open source alternative to the basic list view). https://stackoverflow.com/a/58114167/4824531 – Thomas N Oct 26 '19 at 18:10

1 Answers1

0

If you want to add the images to the ListView by code.Two images for a list view item ,you can refer the code.

  public void Form_Load(object sender, EventArgs e)
            {
                DirectoryInfo dir = new DirectoryInfo(@"Path OF Image");
                foreach (FileInfo file in dir.GetFiles())
                {
                    try
                    {
                        this.imageLists.Images.Add(Image.FromFile(file.FullName));
                    }
                    catch{
                        Console.WriteLine("This is not an image file");
                    }
                }
                this.listViewImage.View = View.LargeIcon;
                this.imageLists.ImageSize = new Size(50, 50);
                this.listViewImage.LargeImageList = this.imageLists;

                for (int j = 0; j < this.imageLists.Images.Count; j++)
                {
                    ListViewItem item = new ListViewItem();
                    item.ImageIndex = j;
                    this.listView1.Items.Add(item);
                }
            }
Bibin
  • 492
  • 5
  • 11