Looping through a Listviews SubItems?
Is there a way to loop through a ListViews SubItems property to Add SubItems. I'd like my program not to have to know in advance how many SubItems to add(to find out in execution, then process). Also why if I use the DOEVENTS it takes twice as long to open the DB?
Code:
Option Explicit
Private conn As ADODB.Connection
Private Sub Load_list()
Dim itemX As ListItem
Dim rs As ADODB.Recordset
Dim i As Integer
Dim intCounter As Integer ' Counter to set Progressbar.Value
'Create New connection
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Biblio.mdb"
Dim w As Integer ' add this line
w = 0 ' this one
'Open the Titles table
Set rs = New ADODB.Recordset
rs.Open "Titles", conn, adOpenKeyset, adLockPessimistic
rs.MoveLast
rs.MoveFirst
With prgLoad
.Max = rs.RecordCount
.Visible = True
End With
ListView1.View = lvwReport
For i = 1 To rs.Fields.Count
ListView1.ColumnHeaders.Add , , rs.Fields(w).Name ' alter this
w = w + 1 ' add this
Next i
Do Until rs.EOF
intCounter = intCounter + 1
prgLoad.Value = intCounter ' Update ProgressBar.
Set itemX = ListView1.ListItems.Add(, , rs.Fields(0))
itemX.SubItems(1) = rs.Fields(1)
itemX.SubItems(2) = rs.Fields(2)
itemX.SubItems(3) = rs.Fields(3)
itemX.SubItems(4) = rs.Fields(4)
Set itemX = Nothing
rs.MoveNext
DoEvents
Loop
' Hide Progressbar
prgLoad.Visible = False
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
Private Sub Command1_Click()
Call Load_list
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Me
End Sub
Private Sub mnuExit_Click()
Form_Unload
End Sub