View Full Version : Loop through listView & update checkbox
lifeson
06-05-2008, 07:54 AM
:help :hi: 
Back again with another listview control question
 
I want a routine that loops through each record in a listview control where the checkbox value is false (unchecked) run some code, then update the checkbox to true (checked): pray2: 
 
I have attached an example
Bob Phillips
06-05-2008, 09:38 AM
Private Sub cmdRun_Click()
Dim lCount As Long
    lCount = lvwExpGuide.ListItems.Count
    
    MsgBox lCount & " items in the list"
    
    With Me.lvwExpGuide
          
        For x = 1 To 5
            If Not .ListItems(x).Checked Then
            
                'run some code
                .ListItems(x).Checked = True
            End If
        Next x
    End With
End Sub
lifeson
06-05-2008, 10:37 AM
Briliantly simple solution as usual XLD :clap: 
 
One last question (for a bit anyway :thumb )
 
How do I select the third item in the list
 
eg
 With Me.lvwExpGuide
 
For x = 1 To lCount
If Not .ListItems(x).Checked Then
 
listID = .ListItems(3)
MsgBox listID & " Done"
.ListItems(x).Checked = True
End If
Next x
End With 
 
The code above lists the third item down but not the 3rd across :think:
 
Do I need to select the item as a seperate routine when the listview changes?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.