标题: LISTVIEW如何显示不同表头 [打印本页] 作者: leoyan76 时间: 2011-1-11 16:28 标题: LISTVIEW如何显示不同表头 我用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作者: asklove 时间: 2011-1-11 16:50
你试试这样行不行:(具体使用方法你可以百度一下:listview控件常用方法)
frm.ColumnHeaders.Clear
For I = 0 To num - 1
frm.ListView.ColumnHeaders.Add , , rst.Fields(I).Name, , 0
Next 作者: leoyan76 时间: 2011-1-12 09:07
可以了谢谢!