永发信息网

VB 中 关于刷新ListView的问题

答案:2  悬赏:10  手机版
解决时间 2021-05-09 16:08
  • 提问者网友:练爱
  • 2021-05-08 19:26

Private Sub Form_Load()

0
DownloadFile " http://00000.net/00000.txt", "C:\tmp.txt"


Dim arrData(200, 5) As String
Dim tmpstr As String
Dim tmparr() As String
Dim i As Integer

i = 0
Open "C:\tmp.txt" For Input As #1 '读取文件
While Not EOF(1)
Line Input #1, tmpstr
If tmpstr <> "" Then
tmparr = Split(tmpstr, "----")

arrData(i, 1) = tmparr(1)
arrData(i, 2) = tmparr(2)
arrData(i, 3) = tmparr(3)
arrData(i, 4) = tmparr(4)

arrData(i, 0) = tmparr(0)
i = i + 1
End If
Wend
Close #1
For i = 0 To 200
Set Itmx = lv.ListItems.Add(, , arrData(i, 0))
For j = 1 To 4
Itmx.SubItems(j) = arrData(i, j)
Next j
Next i
Kill "C:\tmp.txt

End Sub

怎么可以实现 ListView 里的数据一直是新的 不用重启程序

最佳答案
  • 五星知识达人网友:十鸦
  • 2021-05-08 19:56

Private Sub Command1_Click()
DownloadFile " http://00000.net/00000.txt", "C:\tmp.txt"



Dim arrData(200, 5) As String
Dim tmpstr As String
Dim tmparr() As String
Dim i As Integer


i = 0
Open "C:\tmp.txt" For Input As #1 '读取文件
While Not EOF(1)
Line Input #1, tmpstr
If tmpstr <> "" Then
tmparr = Split(tmpstr, "----")


arrData(i, 1) = tmparr(1)
arrData(i, 2) = tmparr(2)
arrData(i, 3) = tmparr(3)
arrData(i, 4) = tmparr(4)


arrData(i, 0) = tmparr(0)
i = i + 1
End If
Wend
Close #1
For i = 0 To 200
Set Itmx = lv.ListItems.Add(, , arrData(i, 0))
For j = 1 To 4
Itmx.SubItems(j) = arrData(i, j)
Next j
Next i
Kill "C:\tmp.txt"




End Sub




Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub


Private Sub Timer1_Timer()
Call Command1_Click
End Sub


全部回答
  • 1楼网友:思契十里
  • 2021-05-08 20:03

把这个程序放到command 事件里,再在timer事件和form_load事件里用command1_click就行了,这样方便控制....

如果只需要自动刷新,就把这个程序直接放timer事件里,把timer的时间设置在1秒以内,就能保证看到的是新的了...

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯