Message 1 of 4
ListView.ListItems 1 based or 0 based?

Not applicable
11-08-2007
06:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was told here recently that .ListItems collection is 0 based
But I have tried numerous times to confirm that and can find no settings
which make it work.
I've tried all four settings for LV.View and none of them make it work
I've tried with and without .ColumnHeaders and neither makes it work....
Can anyone enlighten me on what I'm doing wrong?
I keep getting out of bounds error with oLV.ListItems.Item(0)
using this test ...
(you can replace LogEntry and LogError with Debug.Print
Sub EnumListItems(oLV As ListView)
Dim lChek As Long, sRpt As String
'norman yuan(whom I greatly respect and am sure is right) says ListItems
is zero based but I get out of bounds error on it
'For lChek = 0 To oLV.ListItems.Count - 1
CheckBase1:
On Error GoTo Base1Err
Debug.Print "Try 1 based collection"
For lChek = 1 To oLV.ListItems.Count
If oLV.ListItems.Item(lChek).Selected = True Then
sRpt = sRpt & "Item " & CStr(lChek) & " Selected " & vbCrLf
Else
sRpt = sRpt & "Item " & CStr(lChek) & " Not Selected " & vbCrLf
End If
Next lChek
CheckBase0:
On Error GoTo Base0Err
Debug.Print "Try 0 based collection"
For lChek = 0 To oLV.ListItems.Count - 1
If oLV.ListItems.Item(lChek).Selected = True Then
sRpt = sRpt & "Item " & CStr(lChek) & " Selected " & vbCrLf
Else
sRpt = sRpt & "Item " & CStr(lChek) & " Not Selected " & vbCrLf
End If
Next lChek
Debug.Print "Selected items oLV: " & vbCrLf & sRpt
ExitHere:
On Error GoTo 0
Exit Sub
EnumListItems_Error:
Err.Clear
Resume ExitHere
Base1Err:
Debug.Print "Base-1-Err"
Err.Clear
Resume CheckBase0
Base0Err:
Debug.Print "Base-0-Err"
Err.Clear
Resume ExitHere
End Sub
But I have tried numerous times to confirm that and can find no settings
which make it work.
I've tried all four settings for LV.View and none of them make it work
I've tried with and without .ColumnHeaders and neither makes it work....
Can anyone enlighten me on what I'm doing wrong?
I keep getting out of bounds error with oLV.ListItems.Item(0)
using this test ...
(you can replace LogEntry and LogError with Debug.Print
Sub EnumListItems(oLV As ListView)
Dim lChek As Long, sRpt As String
'norman yuan(whom I greatly respect and am sure is right) says ListItems
is zero based but I get out of bounds error on it
'For lChek = 0 To oLV.ListItems.Count - 1
CheckBase1:
On Error GoTo Base1Err
Debug.Print "Try 1 based collection"
For lChek = 1 To oLV.ListItems.Count
If oLV.ListItems.Item(lChek).Selected = True Then
sRpt = sRpt & "Item " & CStr(lChek) & " Selected " & vbCrLf
Else
sRpt = sRpt & "Item " & CStr(lChek) & " Not Selected " & vbCrLf
End If
Next lChek
CheckBase0:
On Error GoTo Base0Err
Debug.Print "Try 0 based collection"
For lChek = 0 To oLV.ListItems.Count - 1
If oLV.ListItems.Item(lChek).Selected = True Then
sRpt = sRpt & "Item " & CStr(lChek) & " Selected " & vbCrLf
Else
sRpt = sRpt & "Item " & CStr(lChek) & " Not Selected " & vbCrLf
End If
Next lChek
Debug.Print "Selected items oLV: " & vbCrLf & sRpt
ExitHere:
On Error GoTo 0
Exit Sub
EnumListItems_Error:
Err.Clear
Resume ExitHere
Base1Err:
Debug.Print "Base-1-Err"
Err.Clear
Resume CheckBase0
Base0Err:
Debug.Print "Base-0-Err"
Err.Clear
Resume ExitHere
End Sub