通过Dtpicker向listview中添加固定日期数据
首先定义开始 结束日期 listview对象
获得Dtpicker中的选定日期
具体代码如下:
Dim txtSQL As String
Dim Msgtext As String
Dim objrs As adodb.Recordset
Dim addlist As ListItem ‘定义listview的对象
Dim startdate As Date
Dim enddate As Date
startdate = DTPickerStart.Value
enddate = DTPickerEnd.Value
ListView1.ListItems.Clear ‘清空listview上次的数据
txtSQL = "select * from backrecord where backdate between '" & startdate & "'" & " and" & "'" & enddate & "'"
Set objrs = ExecuteSQL(txtSQL, Msgtext)
Do While Not objrs.EOF
Set addlist = ListView1.ListItems.Add(, , objrs.Fields(0).Value)
addlist.SubItems(1) = objrs.Fields(1).Value
addlist.SubItems(2) = objrs.Fields(2).Value
addlist.SubItems(3) = objrs.Fields(3).Value
addlist.SubItems(4) = objrs.Fields(4).Value
objrs.MoveNext
Loop
objrs.Close
括号里一次为(index,key,listview中的第一列数据)
Subitems(i)为各子项数据段