C# ListView 项目图像

标签 c# winforms listview foreach

如何使用 foreach 语句将图像(指定图像)添加到 ListView 中 例如:

foreach(Video entry in videoFeed.Entries) {

listview1.items.add(entry);

listview1.items.image(imageURL);

}

最佳答案

如果您想要为您的ListViewItem 显示图像,那么您需要创建一个ImageList,用图像填充它,分配ImageListListView,然后告诉每个 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/

相关文章:

c# - 为什么参数会这样?

C# 多列列表框

c# - 如何创建新的 Windows 窗体,并将其与已存在的线程关联?

java - 在 Android 中使用 SimpleCursorAdapter 填充 ListView

Android:通过 SimpleAdapter 在 imageview 中显示图像

c# - 将 .NET 应用程序转换为 x86 native 代码

c# - 有没有办法将两个 LINQ 查询合并为一个?

c# - Linq 性能 : does it make sense to move out condition from query?

winforms - Datagridview 列宽

android - 我如何修复 Android 中位置、适配器和 ListView 的这个错误?