Results 1 to 4 of 4

Thread: Adding a label caption to the first column of a listview.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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!

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    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

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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:
    1. 'This code will add the answer to the data collection  LISTVIEW for current activity'
    2.  
    3. ' Step 1 add the students name
    4.  Dim li3 As ListItem
    5. Set li3 = Data.ListViewDataCURRENT.ListItems.Add()
    6. li3.Text = StudentNamePickedLBL.Caption
    7.  
    8. 'Step 2 Add the outcome they did
    9. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , Me.Name
    10.  
    11. 'Step 3 Add the question they did
    12. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , GetQuestionLBL.Caption
    13.  
    14. 'Step 4 Add the answer they picked
    15. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , StudentAnswerLBL.Caption
    16.  
    17. 'Step 5 Add the correct answer for the question
    18. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , QuestionLBL.Caption
    19.  
    20.  
    21. 'Step 6: Add if the student was correct or incorrect
    22.     If StudentAnswerLBL.Caption = QuestionLBL.Caption Then
    23.             Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "Correct"
    24.            
    25.     Else:
    26.             Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "Incorrect"
    27.            
    28.     End If
    29.  
    30.  
    31. 'Step 7 Record how long it took to answer
    32. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , timeLBL.Caption & " Seconds."
    33.  
    34. 'Step 8 Record the date the question was completed
    35. Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , Data.DateLBL.Caption
    36.  
    37.     If StudentAnswerLBL.Caption = QuestionLBL.Caption Then
    38.             Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "3"
    39.            
    40.     Else:
    41.             Data.ListViewDataCURRENT.ListItems(1).ListSubItems.Add , , "1"
    42.            
    43.     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!

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width