【问题标题】:VB.NET - For each checked item in listviewVB.NET - 对于列表视图中的每个选中项目
【发布时间】:2011-09-16 07:02:54
【问题描述】:

这可能也很容易。但是我有这个列表视图,其中包含我列出的 exe 文件。现在,我想依次执行这些 exe 文件,从中检查或不检查项目。

所以,我试过这个:

For each item in listView1.CheckedItems
    Msgbox item.ToString
Next

因为我注意到checkedItems 中的项目包含的内容不多。如果我将它转换为字符串,它最终会出现在 msgbox 中,如下所示:ListViewItem: {Filename.exe}

现在,我显然想要文件名。但是有没有其他方法可以只提取名称?还是我必须剥离字符串才能删除 ListViewItem: { 部分?

【问题讨论】:

    标签: vb.net listview contains strip


    【解决方案1】:

    您的第一步应该是咨询documentation of ListViewItem 以了解如何从对象中检索所需信息。

    Text 属性是您所追求的。

    For Each item in listView1.CheckedItems
        MsgBox(item.Text)
    Next
    

    【讨论】:

    • 对不起,intellisense 没有显示 Item 属性。我以为那里没有什么属性 :) 这很好地清除了它 :) 我猜你每天都会学到一些新东西! :)
    【解决方案2】:
    For each item in listView1.CheckedItems
        Msgbox item.Text
    Next
    

    这应该适用于winforms。

    【讨论】:

      【解决方案3】:

      你试过Msgbox item.Text吗?

      【讨论】:

        【解决方案4】:

        您可能正在寻找更多类似的东西。这将有项目和子项目。您将需要一个带有 in 循环的循环来完成此操作。希望这会有所帮助

             Dim x As Integer = 0
             Dim y As Integer = 0
             For Each item In listView1.CheckedItems
                 For Each subitem In listView1.CheckedItems(y).SubItems
                    MsgBox(subitem.Text)
                    x = x + 1
                 Next
              y = y + 1
            Next
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-07-03
          • 1970-01-01
          • 2019-09-21
          • 1970-01-01
          • 1970-01-01
          • 2022-11-07
          • 2018-01-08
          相关资源
          最近更新 更多