VB中listview的用法

2024-11-27 04:14:01
推荐回答(1个)
回答1:

文本文件 1.txt
里面内容是:
李佳
22
文秘
13655555555
张奇
24
经理
13755555555
张佳
22

135555555

Public Sub LVrefresh(Optional ByVal StandardType As Boolean)
Dim intRow As Integer, strTemp As String
Dim fileNo As Integer, fileName As String
Dim Fp As New FileSystemObject
Dim strTs As TextStream

Dim ListItemTemp As ListItem

On Error Resume Next

fileNo = FreeFile

With ListView1
.ColumnHeaders.Clear
.ListItems.Clear

.ColumnHeaders.Add , , "姓名"
.ColumnHeaders(1).Width = 1200
.ColumnHeaders.Add , , "年龄"
.ColumnHeaders(2).Width = 900
.ColumnHeaders.Add , , "职位"
.ColumnHeaders(3).Width = 2000
.ColumnHeaders.Add , , "联系电话"
.ColumnHeaders(4).Alignment = lvwColumnLeft
.ColumnHeaders(4).Width = 2000

intRow = 1

fileName = IIf(Left(App.Path, 1) = "\", App.Path & "1.txt", App.Path & "\1.txt")

Set strTs = Fp.OpenTextFile(fileName)

strTemp = strTs.ReadLine

Do While Err.Number = 0

If intRow = 1 Then
Set ListItemTemp = .ListItems.Add(, , strTemp)
Else
ListItemTemp.SubItems(intRow - 1) = strTemp
End If

If intRow = 4 Then
intRow = 1
Else
intRow = intRow + 1
End If
strTemp = strTs.ReadLine
Loop

End With
End Sub

Private Sub Command1_Click()
LVrefresh
End Sub