VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Delete multiple selected rows in a listview

by Peter Schmitz (2 Submissions)
Category: OLE/COM/DCOM/Active-X
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Always wanted to delete multiple rows in a listview by using checkboxes to select which ones to delete? Then this is the simple solution.
Might work on earlier versions of VB, too.

Rate Delete multiple selected rows in a listview

Private Sub cmdDelete_Click()
Dim i As Integer
 
 With Listview1
 
 ' The trick: We step backwards through 
 ' the array.
 ' The reason you always get an 'out of 
 ' bound' error is because at a certain 
 ' point the value of i will equal 0,
 ' or be greater than the number of rows
 ' left. (We set i with the initial
 ' row.count, and then start deleting
 ' from that count).
 ' We avoid that by stepping
 ' backwards :)
 For i = .ListItems.Count To 1 Step -1
 If .ListItems(i).Checked Then
  .ListItems.Remove (i)
 End If
 Next i
 End With
End Sub

Download this snippet    Add to My Saved Code

Delete multiple selected rows in a listview Comments

No comments have been posted about Delete multiple selected rows in a listview. Why not be the first to post a comment about Delete multiple selected rows in a listview.

Post your comment

Subject:
Message:
0/1000 characters