vb.net 自动刷新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14952226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatically refresh
提问by Pauline
I want to ask how to auto refresh/update the listview using timer in vb.net.. Give me an idea or steps, or code. Here's my code in timer:
我想问一下如何在 vb.net 中使用计时器自动刷新/更新列表视图。给我一个想法或步骤,或代码。这是我的计时器代码:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.Open()
Timer1.enabled = False
Timer1.interval = 5000
Dim strquery As String = "Select * " & _
"from software "
Dim myCommand As New OdbcCommand(strquery, conn)
Dim myReader As OdbcDataReader
myReader = myCommand.ExecuteReader
ListView1.Items.Clear()
If myReader.HasRows = True Then
'ListView1.BeginUpdate()
While myReader.Read
Dim ListView As ListViewItem
ListView = ListView1.Items.Add(myReader("log_type").ToString())
ListView.SubItems.Add(myReader("log_desc").ToString())
ListView.SubItems.Add(myReader("log_details").ToString())
ListView.SubItems.Add(myReader("log_date").ToString())
ListView.SubItems.Add(myReader("software_desc").ToString())
ListView.SubItems.Add(myReader("software_name").ToString())
ListView.SubItems.Add(myReader("develop_date").ToString())
ListView.SubItems.Add(myReader("last_update").ToString())
End While
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 1000
Timer1.Enabled = False
ListView1.Refresh()
ListView1.Items.Add(DateTime.Now.ToLongTimeString() + "," + _
DateTime.Now.ToLongDateString())
End Sub
This timer doesnt work. Is there anything way to auto update or auto refresh a listview?.
这个计时器不起作用。有什么方法可以自动更新或自动刷新列表视图?
回答by SysDragon
You need to enable the Timer again at the end:
您需要在最后再次启用计时器:
Timer1.Enabled = True
If not, the timer wont work. Timer1.Enabled = Falsedesactivate the Timer.
如果没有,计时器将无法工作。Timer1.Enabled = False停用定时器。

