我正在尝试通过委派更新DataGridView。这是一个简单应用程序的一部分,但初始查询需要4-5秒才能生成。我想使用FillSchema来构建DataGridView,这样应用程序就可以快速启动,然后更新数据。这是我第一次尝试代表,所以欢迎所有的批评。
Private Sub LoadGrid(ByVal loadType As String)
StringBuild()
If loadType = "Schema" Then
da.FillSchema(ds, SchemaType.Source, "Requests")
Else
da.Fill(ds, "Requests")
End If
End Sub
Private Sub LoadGridAsync()
Dim del As New delLoadGrid(AddressOf LoadGrid)
Dim cb As New AsyncCallback(AddressOf LoadGridCallback)
Dim result As IAsyncResult
result = del.BeginInvoke("Full", cb, del)
End Sub
Private Sub LoadGridCallback(ByVal result As IAsyncResult)
Dim delS As delLoadGrid
Dim delR As New delRefreshGrid(AddressOf RefreshGrid)
delS = CType(result.AsyncState, delLoadGrid)
delS.EndInvoke(result)
Invoke(delR)
End Sub
Private Sub RefreshGrid()
dgvSign.Update()
End Sub
我可以在RefreshGrid sub中使用debug.print命令,它肯定会触发。为什么它不更新,有什么想法吗?
发布于 2012-03-14 03:17:11
我自己并不经常使用DataGrid,但我认为Update方法与将数据放入控件没有任何关系,只是它如何重新绘制。因此,在将数据加载到后台线程之后,仍然需要实现一些逻辑来将其放入网格中。您需要一些代码来设置RefreshGrid中的DataSource。
https://stackoverflow.com/questions/9690123
复制相似问题