0

这似乎很容易,但我现在对此有疑问。

我想要做的是在列表视图的第二列中查找特定条目,然后如果找到该特定条目,则删除找到该条目的行。

这是我的代码:

      Dim lvSubItems As ListViewItem.ListViewSubItem

      For Each lvSubItems In lvConnectedClients.Items(lvConnectedClients.Items.Count - 1).SubItems

            If lvSubItems.Text = CType(clientSocket.Client.RemoteEndPoint, IPEndPoint).Address.ToString Then

                  ' This is not the correct way.
                  lvConnectedClients.Items.Remove(lvSubItems)

            End If

      Next

提前致谢!

4

2 回答 2

0

我认为你在正确的轨道上,下面对我有用(添加“作为 ListViewItem”)。让我知道。

For Each li As ListViewItem In ListView1.Items

        If li.Text = "test 7" Then

        ListView1.Items.Remove(li)

        End If

Next

我创建项目的代码:

Dim i As Integer = 0

    For i = 0 To 9

        Dim li As New ListViewItem("test " & i)


        ListView1.Items.Add(li)


    Next
于 2013-01-16T22:16:47.437 回答
0
 For Each lvSubItems As Object In ListView1.Items
            If lvSubItems.Text = "test" Then
                ListView1.Items.Remove(lvSubItems)
            End If
 Next

或者

For Each lvSubItems As ListViewItem In ListView1.Items

        If lvSubItems.SubItems(1).Text = "1" Then
            ListView1.Items.Remove(lvSubItems)
        End If
    Next
End Sub
于 2013-01-16T22:25:16.843 回答