我想问如何在 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
这个计时器不起作用。有什么方法可以自动更新或自动刷新列表视图?