从ListView中仅删除选中的项目? (RemoveAt无法正常工作.) [英] Deleting only checked items from ListView? (RemoveAt not working right.)

查看:54
本文介绍了从ListView中仅删除选中的项目? (RemoveAt无法正常工作.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从ListView窗口中删除选中的项目:

I'm trying to delete checked items from a ListView window:

For intCnt = lsvCollection.Items.Count To 1 Step -1  ' Go backwards so removing items doesn't shuffle their positions.
	If lsvCollection.Items(intCnt - 1).Checked Then
	        lsvCollection.Items.RemoveAt(intCnt - 1)
...

问题是,实际上删除所有内容的唯一迭代是最后一个(" lsvCollection.Items.RemoveAt(0)"),它删除了窗口中的所有条目,而不仅仅是一个指示. (intCnt-1)"的任何其他值 什么都不做.

Problem is, the only iteration that actually removes anything is the last one ("lsvCollection.Items.RemoveAt(0)"), which removes ALL entries in the window, not just the one indicated. ANY other value for "(intCnt-1)" does nothing.

我必须执行此错误,但不确定如何解决. TIA

I must be implementing this wrong but not sure how to fix. TIA

推荐答案

必须存在一些影响您的内容的显示,因为它应该可以工作

there must be something that is influencing this that you aren't showing since this should work

对此进行了测试,没有任何问题

just tested this, without any problem

  For intCnt = ListView1.Items.Count To 1 Step -1
            If ListView1.Items(intCnt - 1).Checked Then
                ListView1.Items.RemoveAt(intCnt - 1)
            End If
        Next


以上按预期工作


above worked as expected


这篇关于从ListView中仅删除选中的项目? (RemoveAt无法正常工作.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆