DataGrid.AutoGenerateColumns Property

 

Gets or sets a value that indicates whether the columns are created automatically.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

member AutoGenerateColumns : bool with get, set

Property Value

Type: System.Boolean

true if columns are created automatically; otherwise, false. The registered default is true. For more information about what can influence the value, see DependencyProperty.

Setting AutoGenerateColumns to true or false creates or removes auto-generated columns. When the AutoGenerateColumns property is set to true, the AutoGeneratingColumn event will be raised for each column that is created. You can change or cancel the column being created in the AutoGeneratingColumn event handler.

When auto-generation of all columns is complete, the AutoGeneratedColumns event is raised.

System_CAPS_noteNote

DataGrid cannot auto-generate columns when the source is XML data. In this case, create a custom Columns collection. For an example, see DataGridTextColumn.

The following example shows how to auto-generate columns and change the columns at creation time in the AutoGeneratingColumn event handler.

<!-- The DataGrid.DataContext is a DataTable that contains a list of customers.  The DataTable columns are  
     Title, FirstName, MiddleName, LastName, Suffix, CompanyName, EmailAddress, and Phone.-->
<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="True" AutoGeneratingColumn="DG1_AutoGeneratingColumn" />
No code example is currently available or this language may not be supported.

.NET Framework
Available since 4.0
Silverlight
Available since 2.0
Return to top
Show: