[英]Foreach on ImageListView in C#
I am trying to implement a foreach loop on a ListViewItem. 我试图在ListViewItem上实现一个foreach循环。
foreach(ListViewItem eachItem in ThumbnailLists.SelectedItems)
{
// do something
}
The problem is my ThumbnailLists
is of type Manina.Windows.Forms.ImageListViewItem
and it couldn't be converted to System.Windows.Forms.ListViewItem
. 问题是我的
ThumbnailLists
类型为Manina.Windows.Forms.ImageListViewItem
,并且无法将其转换为System.Windows.Forms.ListViewItem
。 Therefore, I couldn't use the foreach on my thumbnail. 因此,我无法在缩略图上使用foreach。 Is there any way I could by pass this or fix this?
有什么办法可以绕过这个问题或解决这个问题吗?
I tried something like this: 我尝试过这样的事情:
foreach (ImageListViewItem eachItem in ThumbnailLists.SelectedItems)
{
ThumbnailLists.Items.Remove(eachItem);
}
However, it doesn't delete all the thumbnails, only leaving one left. 但是,它不会删除所有缩略图,只留下一个。 It only works if there are less than 5 thumbnails.
仅当缩略图少于5个时才有效。
您可以尝试以下方法:
this.ThumbnailLists.Clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.