如何使用 foreach 语句将图像(指定图像)添加到 ListView 中 例如:
foreach(Video entry in videoFeed.Entries) {
listview1.items.add(entry);
listview1.items.image(imageURL);
}
最佳答案
如果您想要为您的ListViewItem 显示图像,那么您需要创建一个ImageList,用图像填充它,分配ImageList 到 ListView,然后告诉每个 ListViewItem 使用列表中的哪个图像:
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";
您可以在此 MSDN article 中阅读有关 ListViewItem 以及如何设置/使用图像的更多信息或者在这个MSDN tutorial .
关于C# ListView 项目图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17381725/