在运行时将项目添加到列表视图

在运行时将项目添加到列表视图

问题描述:

当我使用添加新值到ListView:

When I add new values to a listview using :

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

唯一的问题是,这只是显示在ListView空白的新线,任何想法如何正确地更新它?

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

通常情况下,我使用的记录如此简单清楚,然后重新填充数据,但我需要的用户能够将条目添加到列表视图。我会再通过列表视图循环增加值TOT他DB只有当用户完成修改列表视图。

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.

假设你的ListView的.View属性设置为报告,下面就一对夫妇行添加到控制和设置子项的文字。

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