Remove Multiple Checked Items from Listview in VB6.0 Easy Tips

If you try to Remove checked items from Listview through loop, you will face problem of wrong items deletion. So, the solution is described in this post with details' description.

Whenever you create an application in Visual Basic 6.0, and want to implement your application with data or record through list, then you have to require some component or tool like Listview, FlexGrid, MSHFlexGrid etc. In this control you can add, delete or edit items easily.

But SKOTechLearn describe the way where you can Remove Multiple Checked Items from Listview in VB6.0 easily.

If you want to proceed only one by one or single item’s removal process, then you can check it from easily edit or delete selected listview items in vb6.0.

But, if you want to remove or delete multiple checked items, then you have to follow the steps describe by SKOTechLearn.

Show Files' Icons or Image in Listview Easily.

Suppose, this control contain some records and there is a problem to remove of some selected checked item. First you have to implement in Properties of this control like bellow.
ListView CheckBoxes Setting in VB6.0
ListView CheckBoxes Setting
You have to enable “CheckBoxes=True” from Properties windows. Then proceed with following way.

Dynamically add data in ListView with simple way. 

Add some records in loop through code:
Private Sub AddItems_Cmd_Click()
  'Here MyListVBox1 is Listview Control
  Dim i As Integer
  i = 1
  While Not i = 10
      MyListVBox1.ListItems.Add , , Right("0000" & i, 4)
      MyListVBox1.ListItems(i).ListSubItems.Add , , "A" & i
      MyListVBox1.ListItems(i).ListSubItems.Add , , Right("0000" & i, 4) & "-" & Val(Replace(Format(Now, "hh:mm:ss"), ":", "")) + i
      i = i + 1
End Sub

Add Items in Listview in Vb6.0
Add some records
Now we select some items for deletion.

Note: If you try to remove data from ascending order like from top to bottom, then it will remove wrong items. You have to proceed from Bottom to top means you have to create a loop which start from bottom to top.

So, we write code for deletion from Bottom to Top Loop. For this process, we drag a button and write code inside it, like bellow.
Private Sub RemoveItems_cmd_Click() 
   Dim rm1 As Integer
   rm1 = MyListVBox1.ListItems.Count
   While rm1 > 0
       If MyListVBox1.ListItems(rm1).Checked = True Then
           MyListVBox1.ListItems.Remove (rm1)
       End If
       rm1 = rm1 - 1
   MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub

Remove Checked Items From Listview in VB6.0
Remove Checked Items
When you write code inside “RemoveItems_cmd” and run application,  and press this button. The checked record will be deleted like above image.

Get ListView selected row data in TextBox.

If you want to store deleted item or show it on another ListViewBox then, just add this control on application and write the following code for it.
Private Sub RemoveItems_cmd_Click()
  Dim rm1, ls2 As Integer
  ls2 = 1
  rm1 = MyListVBox.ListItems.Count
  While rm1 > 0
      If MyListVBox.ListItems(rm1).Checked = True Then
        'add checked item in another listview control
        MyListVBox2.ListItems.Add , , MyVListBox.ListItems(rm1).Text
        MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(1)
        MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(2)

        MyListVBox1.ListItems.Remove (rm1)

        ls2 = ls2 + 1
    End If
    rm1 = rm1 - 1
 MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub
Suppose my second Listview is “MyListVBox2” then we first add checked item after that we remove that particular items like above code and you will see the output will be just like bellow image.
Get Deleted Items in Other ListView in VB6.0
Get Deleted record in Other ListView
You can easily Get checked record in other List Control.

So, This is the way for Removing or Delete Multiple Checked Items From ListView in VB6.0 with SKOTechLearn.