i am currently developing my vb6 program but having a problem in displaying one listview from two tables .. on first try it runs correctly, it stores my info like name, address, age etc. on their assigned columns but on the second run. the infos multiplies and just placed on the 1st column of the list view :( here is my code on the listview form:
Private Sub Form_Activate()
Set rs = New ADODB.Recordset
With rs
.open "Select * from tblapps , tblappsinfo", cn, 3, 3
ListView1.ListItems.Clear
Do Until rs.EOF
ListView1.ListItems.Add = !Name
ListView1.ListItems.Item(1).ListSubItems.Add = !address
ListView1.ListItems.Item(1).ListSubItems.Add = !tin
ListView1.ListItems.Item(1).ListSubItems.Add = !cel
ListView1.ListItems.Item(1).ListSubItems.Add = !College
ListView1.ListItems.Item(1).ListSubItems.Add = !age
ListView1.ListItems.Item(1).ListSubItems.Add = !Status
ListView1.ListItems.Item(1).ListSubItems.Add = !Salary_Desired
ListView1.ListItems.Item(1).ListSubItems.Add = !Hours_can_work
ListView1.ListItems.Item(1).ListSubItems.Add = !Available_for_work
.MoveNext
Loop
End With
You're not updating the index for the item when you're adding sub-items for subsequent records, it's always adding it to Item(1).
What you want instead in your example is
ListView1.ListItems.Item(ListView1.ListItems.Count)
that way the sub-items are always being added to the newest item.
But be careful! If the Sorted property is true while adding, the most recent may not be the last one. In that case, you could add each item with the name as its own key:
ListView1.ListItems.Add , !Name, !Name
then reference by the key instead of the index
ListView1.ListItems.Item(!Name)
However, it's probably better and easier (avoiding key collision issues) to just turn off sorting before the loop with ListView1.Sorted = False and turn it back on after the loop with ListView1.Sorted = True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With