【问题标题】:vb.net loop through selected items Listboxvb.net 循环遍历选定的项目列表框
【发布时间】:2021-06-24 09:08:58
【问题描述】:

我正在尝试遍历我的 ListBox1 的所有选定项目。问题是我的代码保持不变SearchFolder = ItemSelected

If ListBox1.SelectedIndex > -1 Then
                For Each Item As Object In ListBox1.SelectedItems

                    Dim ItemSelected = CType(ListBox1.SelectedItem.Item("Path"), String)
                    SearchFolder = ItemSelected

                    Dim dirInfo As New IO.DirectoryInfo(SearchFolder)
                    Dim files As IO.FileInfo() = dirInfo.GetFiles()
                    Dim file As IO.FileInfo

                    docImage = (ImageList1.Images.Count - 1)
                    Dim items As New List(Of ListViewItem)

                    For Each file In files
                        Dim filename As String = file.Name.ToString

                        If file.Extension = ".pdf" Then
                            foundList = PDFManipulation.GetTextFromPDF2(SearchFolder + filename, SearchRegX)
                            If foundList = True Then
                                items.Add(New ListViewItem(New String() {"", filename.ToString}, docImage))
                            End If
                        End If
                    Next
                    ListView1.Items.AddRange(items.ToArray)

                Next
            End If

【问题讨论】:

    标签: vb.net listbox selecteditem


    【解决方案1】:

    用线:

    Dim ItemSelected = CType(ListBox1.SelectedItem.Item("Path"), String)

    您将忽略循环中的项目并选择第一个选定的项目。

    您应该将其替换为:

    Dim ItemSelected = CType(Item("Path"), String)
    

    变量Item 是您在For Loop 中声明的变量

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多