Private Sub Form_Load()
On Error GoTo ErrProceed
Dim ObjConnTmp As New ADODB.Connection, DataSource As String
DataSource = "数据库名"
ObjConnTmp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &DataSource &""
ObjConnTmp.Open
Dim ObjTmpRs As New ADODB.Recordset
Set ObjTmpRs.ActiveConnection = ObjConnTmp
ObjTmpRs.CursorType = adOpenDynamic
ObjTmpRs.LockType = adLockOptimistic '设置游标类型
StrTmpSQL = "Select * from 数据库表名"
ObjTmpRs.Open StrTmpSQL
FrmMain.ListView1.View = lvwReport
FrmMain.ListView1.ColumnHeaders.Clear
Call ModListView.SubListViewHeader(FrmMain.ListView1, ObjRsTmp) '加标题
FrmMain.ListView1.ListItems.Clear
Call ModListView.SubListViewListItem(FrmMain.ListView1, ObjRsTmp, "End") '加内容
ObjRsTmp.Close: Set ObjRsTmp = Nothing
ObjConnTmp.Close: Set ObjConnTmp = Nothing
Exit Sub
ErrProceed:
MsgBox "程序发生错误,原因如下:" &vbCrLf &Err.Description
End Sub
Public Sub SubListViewHeader(ByVal ListViewName As ListView, ByVal ObjRs As ADODB.Recordset)
'功能:将相应的记录的 标题加到ListView中去
Dim clmX As ColumnHeader
'设置显示方式
'ListViewName.View = lvwReport
'要想显示出网格,请在属性/通用/网格行 设置
nCounter = ObjRs.Fields.Count - 1
' Dim nWidthGroup() As Integer
' ReDim Preserve nWidthGroup(nCounter)
Dim nWidthGroup(8) As Integer
k = 100
nWidthGroup(0) = k * 6 '[编号]
nWidthGroup(1) = k * 30 '[名称]
nWidthGroup(2) = k * 11 '[大小]
nWidthGroup(3) = k * 8 '[类型]
nWidthGroup(4) = k * 20 '[修改日期]
nWidthGroup(5) = k * 20 '[记录日期]
nWidthGroup(6) = k * 0 '[文件]
For i = 0 To nCounter
nWidth = nWidthGroup(i)
Set clmX = ListViewName.ColumnHeaders.Add(, , ObjRs.Fields(i).Name, nWidth)
Select Case ObjRs.Fields(i).Name
Case "类型"
clmX.Alignment = lvwColumnCenter
Case "大小"
clmX.Alignment = lvwColumnRight
End Select
Next
End Sub
Public Sub SubListViewListItem(ByVal ListViewName As ListView, ByVal ObjRs As ADODB.Recordset, ByVal StrLocate As String)
'功能:将相应的记录的 内容加到ListView中去
'StrLocate 用来定位新加记录在原ListView中的相对位置 Begin,开头 End 结尾
Dim itmX As ListItem
'设置显示方式
'ListViewName.View = lvwReport
'要想显示出网格,请在属性/通用/网格行 设置
'加内容
If ObjRs.EOF And ObjRs.BOF Then Exit Sub
ObjRs.MoveFirst
Do Until ObjRs.EOF
If StrLocate = "End" Then
Set itmX = ListViewName.ListItems.Add(, , ObjRs(0))
Else
Set itmX = ListViewName.ListItems.Add(1, , ObjRs(0))
End If
'向列表中加入数据
For i = 1 To ObjRs.Fields.Count - 1
StrSubItem = FunNullConvert(ObjRs(i))
Select Case ObjRs.Fields(i).Name
Case "大小" '如果是文件大小,则格式化其显示方式为加上千分位
StrSubItem = Format(CLng(StrSubItem), "#,###")
Case "修改日期", "记录日期"
If StrSubItem <>"" Then StrSubItem = FormatDateTime(CDate(StrSubItem), vbGeneralDate)
End Select
itmX.SubItems(i) = CStr(StrSubItem)
Next i
ObjRs.MoveNext
Loop
End Sub
ListViewItem listViewItem = new ListViewItem(number)listViewItem.SubItems.Add(name)
listViewItem.SubItems.Add(id)
listViewItem.SubItems.Add(address)
listViewItem.SubItems.Add(phone)
listViewItem.SubItems.Add(admission_time)
listViewItem.SubItems.Add(departments)
listViewItem.SubItems.Add(classes)
listViewItem.SubItems.Add(birthday)
listView1.Items.Add(listViewItem)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)