i.Newbie i.Newbie - 25 days ago 7
Vb.net Question

How to know if listview.item with index 2 is added or not

I'm trying to indetify by button click if

listview2.item(2)
exists on
listview2
or not:

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles
Button8.Click
If ListView2.Items.Count.Equals(2) Then
TextBox1.Text = "Row with index 2 is found"
End If
End Sub


ListView2.Items.Count.Equals(2)
doesn't solve it.

Answer Source

Item(2) is actually the third one as the index of the items starts with 0. If you want to check if item with the index 2 is there you need to check if the items count is at least 3.

If ListView2.Items.Count >=3 Then
    TextBox1.Text = "Row with index 2 is found"
End If