Skip to main content

DataControlBase.ColumnsSource Property

Gets or sets the source from which the grid generates columns. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v22.1.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core


public IEnumerable ColumnsSource { get; set; }

Property Value

Type Description

The source from which the grid generates columns.


You can define columns in a ViewModel and display them in the GridControl. To do this, follow the steps below:

  1. Create a collection of grid columns in a ViewModel.
  2. Specify a data template that generates columns:

        <DataTemplate x:Key="DefaultColumnTemplate">
            <dxg:GridColumn FieldName="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}"/>
  3. Assign the column collection to the ColumnsSource property and the column template to the ColumnGeneratorTemplate property:

    <dxg:GridControl ...
                     ColumnsSource="{Binding Columns}" 
                     ColumnGeneratorTemplate="{StaticResource DefaultColumnTemplate}"/>

When you reorder columns in the GridControl, the order of items in the collection bound to the ColumnsSource property does not change. Use the BaseColumn.VisibleIndex property to get column positions and process them in your collection.

Refer to the following help topic for more information: How to: Bind the Grid to a Collection of Columns.

See Also