Denvar
Denvar

Reputation: 202

adding items to listview at runtime

When I add new values to a listview using :

    Set lstView = ListView(0).ListItems.Add(, , txtName)
    lstView.ListSubItems.Add , , txtValue
    lstView.Refresh

The only problem is that this only displays a blank new line in the listview, any idea how to update it correctly?

Normally I am using a recordset so simply clear then repopulate the data but I need the user to be able to add entries to the listview. I will then cycle through the listview adding the values tot he DB only once the user has finished amending the listview.

Thanks in advance for any help.

Upvotes: 2

Views: 59980

Answers (1)

Jim H.
Jim H.

Reputation: 5579

Assuming the .View property of your ListView is set to "Report", the following will add a couple of rows to the control and set the sub item text.

Dim li As ListItem

With ListView1
    .ColumnHeaders.Add , , "One"
    .ColumnHeaders.Add , , "Two"
    .ColumnHeaders.Add , , "Three"

    Set li = .ListItems.Add(, , "Row1Item1")
    li.SubItems(1) = "Row1Item2"
    li.SubItems(2) = "Row1Item3"

    Set li = .ListItems.Add(, , "Row2Item1")
    li.SubItems(1) = "Row2Item2"
    li.SubItems(2) = "Row2Item3"
End With

Upvotes: 7

Related Questions