Problem when changing a bindingsource of a datagridview

0

The problem that arises is the following:

When I change the BindingSource of a DataGridView in vb.net in a BackgroundWorker , I get the following error:

  

system indexoutofrangeexception index 0 does not have a value, in System.Windows.Forms.CurrencyManager.gey_Item (Int32idex) in System.Windows.Forms.DataGridView.DataGridViewDataConection.GetError (Int32 rowIndex "

The error does not always jump, there are times when it works correctly, but when I make the change often, the error jumps in. Does anyone know why? How to solve the error? The bindingsource is updated by a datatable by a query something like this:

    Dim b as new bindingsource
dim data as new datatable
dim datagrid as new datagridview
datagrid.datasource = b
b.datasource = data
AddHandler aplicarndocambios.DoWork, AddressOf procesoderellenado
Public aplicarndocambios As System.ComponentModel.BackgroundWorker = New System.ComponentModel.BackgroundWorker
Sub procesoderellenado()
dim adap as new mysqldataadapter ("consulta")
adap.Fill(data)
end sub

In the adapt part, skip a bit of code, but basically do the query, and update "Data" and it works correctly, the error does not always come out

    
asked by Bernardo Harreguy 01.08.2017 в 14:29
source

1 answer

0

After days of frustration I found the problem, when a datagridview is edited from a backgroundworker, the error jumps (supposedly because if I call the update very often, vb.net does not have time to draw the table, when updating once the process has a process time and interrupting it with a second update interrupts the drawing of the previous update process, what I read is that if it is necessary to invoke the update independently with the invoke command and as it was very complex, solve it with a timer

 ' primero defino una variable de tiempo para llevar un conteo para realizar una consulta
 Dim tiempoderecargado as  integer
 Dim rellenarpendiente as boolean 
'Cuando se requiera realizar el quiery de la base de datos y actualizar los datos en los campos se llama a la siguiente sub
 Sub rellenado
 If tiempoderecargado = 0 then 
Tiempoderecargado = 1
 Else 
Rellenarpendiente=true
 End if 
End sub
 'Seguido el timer para controlar un reposo en cada consulta, de esta forma no saturó el servidor de base de datos y no se cuelga el programa 
Private Sub timer1_Tick(sender As System.Object, e As System.EventArgs) Handles timer1.Tick
            If tiempoderecargado > 0 Then
                If tiempoderecargado = 1 or( rellenarpendiente and tiempoderecargado= 100)Then
                 Using adaptador as new mysqladapter("consulta sal")
                Adaptador.fill(data)
                End using

                End If
                tiempoderecargado += 1
                If tiempoderecargado > 100 Then
                    rellenarpendiente= true

                    tiempoderecargado = 0
                End If
            End If

I hope you serve them

    
answered by 06.08.2017 / 03:43
source