I have a datagridview on a windows form. I have a bindingsource and datatable which are created at runtime which I intend to use to bind and keep my datagridview updated.
When debugging I see that my datatable is being populated with rows. I can also see my bindingsource's datasource has data when you open the visualizer.
My issue is that my datagridview stays blank and never seems to get any of the data that my datatable and bindingsource are getting.
Code Sample:
Private bs1 As New BindingSource
Private TraysToScanDatatable As New DataTable
in my constructor
TraysToScanDatatable.Columns.Add(New DataColumn("time", GetType(DateTime)))
TraysToScanDatatable.Columns.Add(New DataColumn("scanner", GetType(Integer)))
TraysToScanDatatable.Columns.Add(New DataColumn("traynumber", GetType(Integer)))
bs1.DataSource = TraysToScanDatatable
UpdateDataGridView(TraysToReadDataGridView, bs1.DataSource) 'if I do not set my datagridview with a delegate here then I cannot update the binding source in the timer.
update timer logic
TraysToScanDatatable.Rows.Add(New Object() {DateTime.Now, 1, lastScanner1TrayReceived})
Me.bs1.DataSource = TraysToScanDatatable
me.bs1.MoveLast
and my updatedatagridview routine
Public Sub UpdateDataGridView(ByVal control As DataGridView, ByVal newdata As DataTable)
If Not control.InvokeRequired Then
control.DataSource = newdata
Else
Invoke(New Action(Of DataGridView, DataTable)(AddressOf UpdateDataGridView), control, newdata)
End If
End Sub