A
A
Alexander Kovalevich2016-04-20 00:27:07
.NET
Alexander Kovalevich, 2016-04-20 00:27:07

How to delete row in ListView that does not contain value in SubItem?

How to delete a row in a ListView that does not contain a value in a SubItem, and leave those that are equal to a variable?

For Each lvi As ListViewItem In ListViewZ.Items
                        If lvi.SubItems(4) <> Variables.UserCity Then
                            ListViewZ.Items.Remove()
                        End If
                    Next

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maa-Kut, 2016-04-20
@DeusEx_Machine

For example, like this (all subelements are checked):

For Each lvi As ListViewItem In ListViewZ.Items
    Dim found As Boolean = False

    For Each si As ListViewItem.ListViewSubItem In lvi.SubItems
        If si.Text = Variables.UserCity Then
            found = True
            Exit For
        End If
    Next

    If Not found Then
        lvi.Remove()
    End If
Next

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question