Vb.net 在背景中填充dgv。

Vb.net 在背景中填充dgv。,vb.net,datagridview,backgroundworker,Vb.net,Datagridview,Backgroundworker,我有一个由sp填充的dgv,所有这些都是用向导创建的。因为填充大约需要10秒钟,我想在后台使用backgroundworker。我试过: Public Class frmStart Delegate Sub updateDGV() Private Sub frmStart_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load BackgroundWorker1.

我有一个由sp填充的dgv,所有这些都是用向导创建的。因为填充大约需要10秒钟,我想在后台使用backgroundworker。我试过:

Public Class frmStart
Delegate Sub updateDGV()

Private Sub frmStart_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

    BackgroundWorker1.WorkerSupportsCancellation = True
    BackgroundWorker1.RunWorkerAsync()

End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork

    Me.Invoke(New updateDGV(AddressOf UpdatingForm))

End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object , _
ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _
Handles BackgroundWorker1.RunWorkerCompleted

msgbox("Completed")

End Sub

Private Sub UpdatingForm()

    Try
        me.tableadapter.fill(me.dataset.table)
    Catch ex As Exception
        MsgBox("Error during loading the dgv")
    Finally
        BackgroundWorker1.CancelAsync()
    End Try

End Sub
End Class
我只看到dgv中的第一行。我如何在后台填写我的整个dgv,代码中的错误在哪里?此外,我希望在填充过程中看到一个弹出窗口,“请等待您的dgv被填充”。你知道怎么做到吗

在修改代码之前,我只有下面一行代码,这是通过编程创建的

me.tableadapter.fill(me.dataset.table)

您的新代码与初始版本相同。Invoke正在强制在UI线程中执行UpdateForm。你可以分成两部分

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    Me.ProductsTableAdapter.Fill(Me.NorthwindDataSet.Products)
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    Me.ProductsBindingSource.ResetBindings(False)
End Sub
也检查一下