To change data programmatically
Note To specify the first table of the DataSet or the first row of the table, use 0.
The following example shows how to change the second entry of the first row of the first table of a dataset by clicking Button1. The DataSet (ds) and Tables (0 and 1) were previously created. Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ds.tables(0).rows(0)(1) = "NewEntry" End Sub
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ds.tables(0).rows(0)(1) = "NewEntry" End Sub
At run time you can use the SetDataBindings property to bind the DataGrid control to a different data source. For example, you may have several ADO.NET data controls, each connected to a different database.
To change the DataSource programmatically
The following example shows how to change the date source using the SetDataBinding method to an ADO.NET data control (adoPubsAuthors) that is connected to the Authors table in the Pubs database. Private Sub ResetSource() DataGrid1.SetDataBinding(adoPubsAuthors, "Authors") End Sub
Private Sub ResetSource() DataGrid1.SetDataBinding(adoPubsAuthors, "Authors") End Sub
Changing Displayed Data at Run Time in the DataGrid Control
Adding Tables and Columns to the Windows Forms DataGrid Control