Back to Devexpress

DataControlBase.ColumnsSource Property

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-9f0750f4.md

latest4.5 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public IEnumerable ColumnsSource { get; set; }
vb
Public Property ColumnsSource As IEnumerable

Property Value

TypeDescription
IEnumerable

The source from which the grid generates columns.

|

Remarks

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:

  3. Assign the column collection to the ColumnsSource property and the column template to the ColumnGeneratorTemplate property:

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.

You can define a collection of GridColumn objects and assign it to the ColumnsSource property. In this case:

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnsSource 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-data-grid-bind-columns-to-viewmodel-collection/CS/ColumnsSample/MainWindow.xaml#L35

xml
</Window.Resources>
<dxg:GridControl ItemsSource="{Binding Source}" ColumnsSource="{Binding Columns}"
                 ColumnGeneratorTemplateSelector="{StaticResource ColumnTemplateSelector}">

wpf-bind-gridcontrol-to-dynamic-data/CS/Unbound_Columns/MainWindow.xaml#L36

xml
ColumnGeneratorTemplateSelector="{StaticResource selector}"
ColumnsSource="{Binding Columns}"
CustomUnboundColumnDataCommand="{Binding OnCustomUnboundColumnDataCommand}"

See Also

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace