Adding a label caption to the first column of a listview.
Hi there everyone. I am working on a program to record my students marks from a math test. I am setting up a listview, it is called ListViewDataCURRENT. Student are shown a question and their answer goes into a label caption called StudentAnswerLBL.
The listview is empty (besides the column headers). I am trying to figure out how to add the item to the second column? I believe it's index is 1.
Would anyone know how to add it. Is it similar to additem for a listbox?
Thanks!
Re: Adding a label caption to the first column of a listview.
ListViewDataCURRENT.ListItems(#).SubItems(1) = StudentAnswerLBL.Caption
or if it's a new item you're adding, when you use Set listitem = ListView1.ListItems.Add(), you'll have the object there, so listitem.SubItems(1) = StudentAnswerLBL.Caption
Re: Adding a label caption to the first column of a listview.
Thank you for your help. My code now looks like this..
VB Code:
'This code will add the answer to the data collection LISTVIEW for current activity'
' Step 1 add the students name
Dim li3 As ListItem
Set li3 = Data.ListViewDataCURRENT.ListItems.Add()
li3.Text = StudentNamePickedLBL.Caption
'Step 2 Add the outcome they did
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , Me.Name
'Step 3 Add the question they did
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , GetQuestionLBL.Caption
'Step 4 Add the answer they picked
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , StudentAnswerLBL.Caption
'Step 5 Add the correct answer for the question
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , QuestionLBL.Caption
'Step 6: Add if the student was correct or incorrect
If StudentAnswerLBL.Caption = QuestionLBL.Caption Then
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "Correct"
Else:
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "Incorrect"
End If
'Step 7 Record how long it took to answer
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , timeLBL.Caption & " Seconds."
'Step 8 Record the date the question was completed
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , Data.DateLBL.Caption
If StudentAnswerLBL.Caption = QuestionLBL.Caption Then
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "3"
Else:
Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "1"
End If
Basically I have 9 columns on the listview, and when students answer a question, the above info goes on the listview. The issue I have now is, it will record the first person that goes. Then after the first person goes, all it will do is record their name, and nothing else. Does that have something to do with the ListItems(1)?
Thanks!
Re: Adding a label caption to the first column of a listview.
Yes the 1 is the index. So for the next row, it would be 2, and so on.