In Listview, you can set property to check mark on particular Items. If you want to show some Checked Items from Listview then you have to learn following process with steps described bellow. ListView provide facility to Check Items which you want to show in another controls.
So, SKOTechLearn describe the easiest way to understand about this process 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.
This process will contain every items with CheckBox. Every single record have its own checkbox.
Steps:
(right Click) >> Properties >> General (Tab) >> Checkboxes (tick mark) >> OK
After setting these properties, add column name and some records.
FirstLstv (Column Header) : 'Sr.No.', 'Product', 'Quantity', 'Price'
Assign same column Header in SecondLstv.
SecondLstv (Column Header) : 'Sr.No.', 'Product', 'Quantity', 'Price'
After assigning Column Header, add some records in FirstLstv.
Code:
So, SKOTechLearn describe the easiest way to understand about this process 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 VB Form:
Drag 2 Listview control and Set both Name as bellow:Control | Name |
Listview1 | FirstLstv |
Listview2 | SecondLstv |
Step 2: Show CheckBox in ListView in VB
For Showing CheckBox in ListView, you have to Setting in Properties like bellow:
How to Show CheckBox in Listview in VB6.0?
How to Show CheckBox in Listview in VB6.0?
1.
First, Right click on this control and click on "Properties" option.
2.
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.
Steps:
(right Click) >> Properties >> General (Tab) >> Checkboxes (tick mark) >> OK
Checkbox Property |
Step 3: Set Listview 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 |
Step 4: Add Record in ListView
Now, you have to add some record in First Listview "FirstLstv". We will add some records in FirstLstv through Form’s ‘Load’ event.Code:
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 ListView Checked Items
For showing Checked items in other Listview. We use "SecondLstv" for this process. There is following code that will check checked items through Loop.Code:
Private Sub AddChecked_Cmd_Click() 'Clear List of SecondLstv SecondLstv.ListItems.Clear 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 Wend '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 like bellow.
There is another way to use this process to add item in Listbox or Combobox.
Also learn Simple way to Delete or Edit Selected Listview Items.
Try yourself to Get Listview Checked Item in Another Listview in visual basic 6.0 code.
0 comments: