Private Delegate sub AddEntryToTableCallback(Byval Entry as SearchResultEntry)
Private Sub bwWorker_DoWork(ByVal sender as Object, ByVal e as DoWorkEventArgs) Handles bwWorker.DoWork
Dim AddEntry As New AddEntryToTableCallback(AddressOf AddEntryToTable)
'...
'.... Some worker code here...'
'...
While True
For Each entry as SearchResultEntry in Response.Entries
AddEntry.Invoke(entry)
Next
End While
End Sub
Private Sub AddEntryToTable(ByVal Entry as SearchResultEntry)
Dim tmpDataRow as DataRow = dtMain.NewRow
'..Assign values to datarow....'
dtMain.Rows.Add(tmpDataRow)
dtMain.AcceptChanges()
if Me.InvokeRequired Then
Me.BeginInvoke(New MethodInvoker(AddressOf RefreshDisplay))
Else
RefreshDisplay()
End If
End Sub
Private Sub RefreshDisplay()
If me.InvokeRequired Then
me.Invoke(New MethodInvoker(AddressOf dgv.Refresh))
Else
dgv.Refresh
End If
End Sub
If I manipulate dgv too much (ie resize, scroll through the added results) while it's still adding, I'll get several of these errors:DataGridView Default Error Dialog
The following exception occured in the DataGridView:
System.InvalidOperationException: BindingSource cannot be its own data source. Do not set the DataSource and Datamember Properties to values that refer back to the BindingSource.
at System.Windows.Forms.BindingSource.get_Count()
at System.Windows.Forms.CurrencyManager.get_Item(Int32_index)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
To replace this default dialog please handle the DataError Event.
It isn't exactly clear where this is getting thrown and I've tried adding a catch for the DataError Event, but I can't Isolate it. The error doesn't seem to hinder the results from continuing to be added. Nor does the error occur at any time after all rows have been added. Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE