Back to Devexpress

DataControlBase.AutoGenerateColumns Property

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-a2e10f86.md

latest7.2 KB
Original Source

DataControlBase.AutoGenerateColumns Property

Gets or sets whether columns should be created automatically for all properties in the underlying data source when the View does not contain any columns. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public AutoGenerateColumnsMode AutoGenerateColumns { get; set; }
vb
Public Property AutoGenerateColumns As AutoGenerateColumnsMode

Property Value

TypeDefaultDescription
AutoGenerateColumnsModeNone

The way columns are generated.

|

Available values:

NameDescription
None

Doesn’t create columns.

| | KeepOld |

Creates columns for all properties in a datasource if the grid doesn’t contain any columns.

| | AddNew |

Creates columns for all properties in a datasource, preserving the columns the grid already contains.

| | RemoveOld |

Creates columns for all properties in a datasource, removing columns the grid already contains.

|

Remarks

This property specifies the way the DataControlBase.PopulateColumns method works.

xaml
<dxg:GridControl x:Name="grid"
                  ItemsSource="{x:Static common:SalesProductData.Data}"
                  AutoGenerateColumns="AddNew">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="State"/>
        <dxg:GridColumn FieldName="Category"/>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TableView x:Name="gridView"/>
    </dxg:GridControl.View>
</dxg:GridControl>

View Example: Generate Columns for All Fields in a Data Source

Set the AutoGenerateColumns property to AutoGenerateColumnsMode.None to prevent columns from being automatically created.

Use the DisplayAttribute or the BrowsableAttribute to prevent the automatic generation of specific properties:

csharp
public class GridDataObject {
    [Browsable(false)]
    public string Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
vb
Public Class GridDataObject
    <Browsable(False)>
    Public Property Id() As String
    Public Property FirstName() As String
    Public Property LastName() As String
End Class

Handle the AutoGeneratedColumns or the AutoGeneratingColumn event to specify column settings (assign column editors, hide individual columns, and so on).

The following code snippets (auto-collected from DevExpress Examples) contain references to the AutoGenerateColumns property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-bind-gridcontrol-to-dynamic-data/CS/VirtualSources.InfiniteAsyncSource/MainWindow.xaml#L15

xml
<dxg:GridControl AutoGenerateColumns="AddNew">
    <dxg:GridControl.ItemsSource>

wpf-data-grid-specify-row-visibility-in-viewmodel/CS/CustomFilteringMVVM/MainWindow.xaml#L30

xml
<dxg:GridControl AutoGenerateColumns="AddNew" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Data}"/>
<dxg:GridControl AutoGenerateColumns="AddNew" Grid.Row="1" x:Name="grid" Grid.Column="1" ItemsSource="{Binding Data}"

wpf-data-grid-display-different-details-based-on-master-row-data/CS/WpfApp30/MainWindow.xaml#L15

xml
<Grid>
    <dxg:GridControl AutoGenerateColumns="AddNew" ItemsSource="{Binding Tasks}">
        <dxg:GridControl.DetailDescriptor>

wpf-data-grid-implement-custom-filtering/CS/CustomFiltering_MVVM/MainWindow.xaml#L25

xml
<dxg:GridControl Grid.Row="1"
                 AutoGenerateColumns="AddNew"
                 ItemsSource="{Binding Items}"

wpf-tree-list-calculate-custom-node-summaries/CS/CustomNodeSummaries_CodeBehind/MainWindow.xaml#L11

xml
<Grid>
    <dxg:TreeListControl AutoGenerateColumns="AddNew" Name="grid">
        <dxg:TreeListControl.View>

wpf-data-grid-create-master-detail-grid-in-code/CS/MasterDetailInCode/MainWindow.xaml.cs#L16

csharp
GridControl gridControl = new GridControl();
gridControl.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew;
gridControl.ItemsSource = Employees.GetEmployees();

wpf-data-grid-create-master-detail-grid-in-code/VB/MasterDetailInCode/MainWindow.xaml.vb#L19

vb
Dim gridControl As GridControl = New GridControl()
gridControl.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew
gridControl.ItemsSource = Employees.GetEmployees()

See Also

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace