这是我正在尝试制作的同步 url 下载程序的一部分。它将 url 列表保存在名为的数据表中tbl
,并绑定到名为 的数据网格视图dgvUrls
。每次遇到死 URL 时,都会将其从数据表中删除。
我已经使用下面的代码重现了该错误。将Button3_Click
100 行添加到数据表中,使其成为 datagridview 的数据源。通过q()
删除第一行一次删除一行。问题是 datagridview 不反映在数据表中所做的更改
Dim tbl = New DataTable
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Add 100 urls, for simplicity i'm adding only integers
tbl.Columns.Add("Urls")
For i = 1 To 100
tbl.Rows.Add(i)
Next
'bind to datagridview so that the end user can see the urls being download/removed from the list
dgvUrls.DataSource = tbl
'start multithread download , for simplicited (of this question) we have only one
Dim t As Thread = New Thread(AddressOf Download)
t.Start()
t.Join()
dgvUrls.Refresh()
End Sub
Private Sub download()
'for simplicity, the 1st 80 urls were dead!
For i = 1 To 80
'we remove the dead urls
tbl.Rows.RemoveAt(0)
Next