I’m trying to update a DataGridView via a Delegate. This is part of a simple application but the initial query takes 4-5 seconds to generate. I want to FillSchema to build the DataGridView so the application launches quickly and then updates the data. This is my first foray into delegates so all critique is welcomed.
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
I can debug.print in the RefreshGrid sub and it definitely fires. Any ideas on why does it not update?
I haven’t used the DataGrid much myself, but I think the Update method doesn’t have anything to do with getting data into the control, just how it repaints. So once you’ve loaded the data on the background thread, you’ll still need to implement some logic to get it into the grid. You need some code to set the DataSource in RefreshGrid.