How to: Autogenerate Columns in a Data-Bound Windows Forms DataGridView Control
The following code example demonstrates how to display columns from a bound data source in acontrol. When the property value is true (the default), a is created for each column in the data source table.
If the DataGridView control already has columns when you set theproperty, the existing bound columns are compared to the columns in the data source and preserved whenever there is a match. Unbound columns are always preserved. Bound columns for which there is no match in the data source are removed. Columns in the data source for which there is no match in the control generate new DataGridViewColumn objects, which are added to the end of the collection.
Compiling the Code
This example requires:
A DataGridView control named customersDataGridView.
Aobject named customersDataSet that has a table named Customers.
References to the, , , and assemblies.