Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Columns are automatically generated when this property is set to true and the DataSource or DataMember properties are set or changed. Columns can also be automatically generated when the property is changed from false to true. If this property is true and the DataSource changes so there are columns that do not match the columns of the previous DataSource value, data in the unmatched columns is discarded. This property is ignored if the DataSource or DataMember properties are not set.
When is set to true, the DataGridView control generates one column for each public property of the objects in the data source. If the bound objects implement the ICustomTypeDescriptor interface, the control generates one column for each property returned by the GetProperties method. Each column header will contain the value of the property name the column represents.
If you set the DataSource property but set to false, you must add columns manually. You can bind each added column to the data source by setting the DataGridViewColumn.DataPropertyName property to the name of a property exposed by the bound objects.
Setting the DataSource in the Windows Forms Designer automatically sets the property to false and generates code to add and bind a column for each property in the data source. The code that is generated at design-time is equivalent to the manually added code shown in the following example. It is not the same as the auto-generation of columns at run-time that occurs when the property is set to true.
The following code example demonstrates how to add columns manually and bind them to a data source when you set to false. In this example, a DataGridView control is bound to a list of Task business objects. Then, columns are added and are bound to Task properties through the DataGridViewColumn.DataPropertyName property. This example is part of a larger example available in How to: Access Objects in a Windows Forms DataGridViewComboBoxCell Drop-Down List.
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)