Question

J'ai un service Web API Odata sur lequel je travaille.Le contrôleur prend en charge ASYNC, mais je ne peux pas sembler trouver de bons exemples sur la manière de charger une ASYNC DataGridView tout en tirant des données du service ODATA.J'ai trouvé ce lien qui m'a un peu ce qu'il y a, mais je ne sais pas comment terminer le reste car je dois actuellement convertir le DataServiceQuery en liste ou dans la base de données échoue. http://msdn.microsoft.com/fr-US / Bibliothèque / DD756367 (v= vs.110) .aspx
Mon code est quelque chose comme ça.

Private Sub getDataButton_Click(sender As Object, e As EventArgs) Handles getDataButton.Click
    ' Define the delegate to callback into the process 
    Dim callback As AsyncCallback = AddressOf OnLogsQueryComplete

    ' Define the query to execute asynchronously that returns  
    ' all customers with their respective orders. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = (From log In context.Logs
                                                                   Select log)

    ' Begin query execution, supplying a method to handle the response 
    ' and the original query object to maintain state in the callback.
    DataGridView1.DataSource = query.BeginExecute(callback, query)
End Sub

Private Function OnLogsQueryComplete(ByVal result As IAsyncResult) As List(Of LogServiceReference.Log)
    ' Get the original query from the result. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = _
        CType(result.AsyncState, DataServiceQuery(Of LogServiceReference.Log))

    Return query.EndExecute(result).ToList()
End Function

Je peux lire / coder C # ou VB, donc si vous avez des exemples de soit je suis toutes les oreilles ...

Était-ce utile?

La solution

Bien que cela ne remplit pas vraiment une grille ASYNC en rangée, il remplit l'ensemble de l'ASYNC de DataSource.Voici le code que j'ai utilisé.

Private gridRows As List(Of LogServiceReference.Log) = New List(Of LogServiceReference.Log)()
Private Delegate Sub UpdateUI()
Private oUpdateUI As UpdateUI

Private Sub getDataButton_Click(sender As Object, e As EventArgs) Handles getDataButton.Click
    Try
        gridRows.Clear()
        DataGridView1.DataSource = Nothing

        oUpdateUI = New UpdateUI(AddressOf DoUpdateUI)

        ' Define the delegate to callback into the process 
        Dim callback As AsyncCallback = AddressOf OnLogsQueryComplete

        ' Define the query to execute asynchronously that returns  
        ' all customers with their respective orders. 
        Dim query As DataServiceQuery(Of LogServiceReference.Log) = (From log In context.Logs
                                                                       Select log)

        ' Begin query execution, supplying a method to handle the response 
        ' and the original query object to maintain state in the callback.
        query.BeginExecute(callback, query)
    Catch ex As Exception

    End Try
End Sub

Private Sub DoUpdateUI()
    DataGridView1.DataSource = gridRows
End Sub

Private Sub OnLogsQueryComplete(ByVal result As IAsyncResult)
    ' Get the original query from the result. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = _
        CType(result.AsyncState, DataServiceQuery(Of LogServiceReference.Log))

    ' Complete the query execution. 
    For Each log As LogServiceReference.Log In query.EndExecute(result)
        gridRows.Add(log)
    Next

    Invoke(oUpdateUI)
End Sub

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top