Image of a CView ListView Element

How to add image (specified image) to listview using foreach statement for example:

foreach(Video entry in videoFeed.Entries) { listview1.items.add(entry); listview1.items.image(imageURL); } 
+4
source share
2 answers

If you want to show an image for a ListViewItem , you need to create an ImageList , fill it with images, assign an ImageList to a ListView , and then tell each ListViewItem which image from the list:

 var listView = new ListView(); // create image list and fill it var imageList = new ImageList(); imageList.Images.Add("itemImageKey", image); // tell your ListView to use the new image list listView.LargeImageList = imageList; // add an item var listViewItem = listView.Items.Add("Item with image"); // and tell the item which image to use listViewItem.ImageKey = "itemImageKey"; 

Learn more about ListViewItem and how to set / use images in this MSDN article or in this MSDN tutorial .

+9
source
  private void Form1_Load(object sender, EventArgs e) { List<string> adress = new List<string>(){"http://www.diseno-art.com/news_content/wp-content/uploads/2012/09/2013-Jaguar-F-Type-1-600x399.jpg" ,"http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-9_2351861k.jpg", "http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-5_2351885k.jpg", "http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-7_2351893k.jpg"}; ImageList il = new ImageList(); foreach (string img in adress) { System.Net.WebRequest request = System.Net.WebRequest.Create(img); System.Net.WebResponse resp = request.GetResponse(); System.IO.Stream respStream = resp.GetResponseStream(); Bitmap bmp = new Bitmap(respStream); respStream.Dispose(); il.Images.Add(bmp); } il.ImageSize = new Size(32, 32); int count = 0; listView1.LargeImageList = il; List<string> names = new List<string>(){"1","2","3","4"}; foreach (string s in names) { ListViewItem lst = new ListViewItem(); lst.Text = s; lst.ImageIndex = count++; listView1.Items.Add(lst); } } 

this is an option so that you do not manually copy each image to your computer, instead you provide a URL and place this image in a new bitmap and add to the list

+2
source

Source: https://habr.com/ru/post/1488872/


All Articles