The following loads a DataTable into a BindingSource, the BindingSource.DataSource is assigned the DataTable
Code:
Public Class Form1
WithEvents bsData As New BindingSource
Code:
bsData.DataSource = LoadMockedServiceItems()
The DataGridView DataSource is the BindingSource
Code:
DataGridView1.DataSource = bsData
Pressing a Button either adds or removes a specific column from the DataTable as per above. When this happens the DataGridView reflects the add or removal of the column NewColumn1.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = DirectCast(bsData.DataSource, DataTable)
If dt.Columns.Contains("NewColumn1") Then
dt.Columns.Remove("NewColumn1")
Else
dt.Columns.Add(New DataColumn With {.ColumnName = "NewColumn1"})
End If
End Sub