VB将数据显示在ListView中

前端之家收集整理的这篇文章主要介绍了VB将数据显示在ListView中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近在学VB,所以把一些东西都记下来,方便以后学习。下面是将数据查处来显示在ListView中

Dim ledrst As ADODB.Recordset
Set ledrst = New ADODB.Recordset
ledrst.Open sql,g_sqlDBConn,adOpenDynamic,adLockPessimistic
ListView_Show Me.ListView1,ledrst,False,False '把查处来的数据集合绑定到listView中

ListView1.ColumnHeaders(1).width = 800 ‘列跟字段对应
ListView1.ColumnHeaders(2).width = 2000
ListView1.ColumnHeaders(3).width = 800
ListView1.ColumnHeaders(4).width = 800
ListView1.ColumnHeaders(5).width = 800
ListView1.ColumnHeaders(6).width = 800
ListView1.ColumnHeaders(7).width = 1200
ListView1.ColumnHeaders(8).width = 4000

'将recordset显示到listview
Public Sub ListView_Show(Lvw As ListView,rs As ADODB.Recordset,Optional isNum As Boolean = False,Optional isCon As Boolean = False) '结束时 recordset 对象关闭,是否进行合同列表第九,十列解密
Dim i As Double
Dim Order As Double
Dim itmX As ListItem '定义一 个ListView的显示项目。
Dim tempstr As String
Dim tmpSum As Double '结算
'Dim tmpRs As ADODB.Recordset
Dim rc As RECT '定义显示listview区域

'On Error GoTo ErrFillListView
Lvw.View = lvwReport
Lvw.Visible = False
Screen.MousePointer = vbHourglass
Lvw.ListItems.Clear '清除ListView的内容?

With Lvw.ColumnHeaders
.Clear
If isNum Then
.Add 1,"序号 ",800
Else
.Add 1,1
End If
If rs.EOF And rs.BOF Then
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).Name = "Code" Or rs.Fields(i).Name = "SchID" Then
.Add i + 2,rs.Fields(i).Name,0
Else
.Add i + 2,Len(rs.Fields(i).Name) * 200
End If
Next

Else
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).Name = "Code" Or rs.Fields(i).Name = "SchID" Then
.Add i + 2,Len(rs.Fields(i).Name) * 200
End If
Next
End If

End With

If rs.EOF And rs.BOF ThenScreen.MousePointer = vbDefaultLvw.Visible = TrueExit Sub

原文链接:https://www.f2er.com/vb/262950.html

猜你在找的VB相关文章