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.
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.
Remove Multiple Items from Listview in VB
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 |
Dynamically add data in ListView with simple way.
Add some records in loop through code:
Private Sub AddItems_Cmd_Click() MyListVBox1.ListItems.Clear '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 DoEvents Wend End Sub
Add some records |
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 DoEvents Wend MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation End Sub
Remove Checked Items |
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() MyListVBox2.ListItems.Clear 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 DoEvents Wend MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation End Sub
Get Deleted record in Other ListView |
So, This is the way for Removing or Delete Multiple Checked Items From ListView in VB6.0 with SKOTechLearn.
0 comments: