Get Listview Checked Item in Another Listview in VB6.0 tips

Get Listview Checked Item in Another Listview in VB6.0 tips

Sometime you need a list from Listview’s selected items. You want to add some items from Listview to another. You want to check items which you want to add in another controls. SKOTechLearn describe the easiest way to understand about this process of how to get Listview checked items in another Listview in VB6.0?

First of all, you have to remember that add Listview control in "Toolbox". Second, Add some records in Listview for further check items process.

Step 1: Add or Drag controls to Form:
Drag 2 Listview control and Set both Name as bellow
Control Name
Listview1 FirstLstv
Listview2 SecondLstv
Step 2: Checkbox setting in ListView Control
First, modify some properties. Right click on this control and click on "Properties" option. Tick mark on "Checkboxes" option from "General" tab of "Property Pages" window. Then press "OK" button. 
This process will contain every items with CheckBox. Every single record have its own checkbox.


(right Click) >> Properties >> General (Tab) >> Checkboxes (tick mark) >> OK
Listview Checkbox Property for checked item
Checkbox Property
Step 3: Set Column Header Name
Set Both control Column Header with same column name.

FirstLstv (Column Header) : 'Sr.No.', 'Product', 'Quantity', 'Price'

Assign same column Header in SecondLstv.

SecondLstv (Column Header) : 'Sr.No.', 'Product', 'Quantity', 'Price'
Assign same Column Header for checked item
Assign same Column Header
After assigning Column Header, add some records in FirstLstv.

Step 4: Add record in First ListView
We will add some records in FirstLstv through Form’s ‘Load’ event.

Private Sub Form_Load()

 With FirstLstv
  .ListItems.Add , , 1
  .ListItems(1).ListSubItems.Add , , "ABCD"
  .ListItems(1).ListSubItems.Add , , 13
  .ListItems(1).ListSubItems.Add , , 1200

  .ListItems.Add , , 2
  .ListItems(2).ListSubItems.Add , , "CDEF"
  .ListItems(2).ListSubItems.Add , , 10
  .ListItems(2).ListSubItems.Add , , 2500

 End With
 'like this add more record

End Sub
Now, we drag command button from "Toolbox" and assign Caption as ‘Add Checked Item’ and assign Name as 'AddChecked_Cmd'. And start coding on its ‘Click’ event.

Login form with MS-Access connection

Step 5: Get Checked Items in SecondLstv
For this process there is following code.

Private Sub AddChecked_Cmd_Click()

 'Clear List of SecondLstv
 Dim i, ik As Integer
 i = 1
 ik = 1
 'i is used for loop in next record.
 'ik use for Next row for add record in SecondLstv.

 While Not i = FirstLstview.ListItems.Count + 1

  'FirstLstv Checked condition if true then add record in SecondLstv.
  If FirstLstv.ListItems(i).Checked = True Then

    SecondLstv.ListItems.Add , , FirstLstv.ListItems(i).Text
    SecondLstv.ListItems(ik).ListSubItems.Add , , FirstLstv.ListItems(i).SubItems(1)
    SecondLstv.ListItems(ik).ListSubItems.Add , , FirstLstv.ListItems(i).SubItems(2)
    SecondLstv.ListItems(ik).ListSubItems.Add , , FirstLstv.ListItems(i).SubItems(3)
    ik = ik + 1
  End If

  i = i + 1

 'Messagebox after completion of Checked item Add Process.
 MsgBox "Checked Record Added Successfully.", vbInformation

End Sub

When you checked item from FirstLstview and click on 'Add Checked Item' button. Then above given code will check one by one item from this list is Checked or not, if the item found checked, then it will add this item to SecondLstview. And after completion of this process, a Process completion message box will appear.
Get Checked Item in another List
Get Checked Item
There is another way to use this process to add item in Listbox or Combobox.

Also learn How to edit or delete selected Listview Items in vb6.0.

Try yourself to get Listview checked item in another Listview in visual basic 6.0 code SKOTechLearn.