|
我用listview显示不同的资料表,数据填充用函数ShowView(frm As Form, strSql As String)实现(代码如下)。 但每次选不同表时,LISTVIEW的表头只会加在原有表头的后面,不会将原有表头去除。我知道需要通过程序将原有表头去除,但我对LISTVIEW的使用方法不熟,因此希望能得到高手的指点,谢谢!
Public Function ShowView(frm As Form, strSql As String)
frm.ListView.ListItems.Clear
Dim I As Integer, num As Integer, Cnt As Integer, FieldsCount As Integer
Dim itmX As ListItem
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset(strSql, dbOpenDynaset, dbSeeChanges)
num = rst.Fields.Count
For I = 0 To num - 1
frm.ListView.ColumnHeaders.Add , , rst.Fields(I).Name, , 0
Next
Do While Not rst.EOF()
Cnt = Cnt + 1
Set itmX = frm.ListView.ListItems.Add(, "K" & rst(0), rst(0), 1, 1)
For I = 1 To num - 1
itmX.SubItems(I) = Nz(rst(I))
Next
rst.MoveNext
Loop
Set itmX = frm.ListView.ListItems.Add(, "TOTAL", "TOTAL", 2, 2)
itmX.SubItems(1) = "TOTAL " & rst.RecordCount & " RECORDERS"
End Function |
|