VB中listview的用法
VB用listview控件,怎么把文件中的数据显示在程序中,然后还可以修改数据了在保存在文件中。谢谢了...
VB用listview控件,怎么把文件中的数据显示在程序中,然后还可以修改数据了在保存在文件中。谢谢了
展开
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
里面内容是:
李佳
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询