Skip to main content
A newer version of this page is available. .

DataControlBase.ColumnGeneratorTemplateSelector Property

Gets or sets the data template selector which chooses a template based on the column’s type. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

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

Declaration

public DataTemplateSelector ColumnGeneratorTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

The column template selector.

Remarks

The DevExpress WPF GridControl supports column binding. The grid can be bound to a collection of objects containing column settings, described in a Model or ViewModel, minimizing the need for ‘code-behind’. The Grid Control generates columns based on column templates. Create multiple templates, one template for each column type. Using a single template, you can create an unlimited number of columns in an unlimited number of grid controls.

To choose the required column template based on the column’s type, use the Data Template Selector assigned to the ColumnGeneratorTemplateSelector property.

using System.Windows;
using System.Windows.Controls;
using Model;

namespace View {
    public class ColumnTemplateSelector : DataTemplateSelector {
        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            Column column = (Column)item;
            return (DataTemplate)((Control)container).FindResource(column.Settings + "ColumnTemplate");
        }
    }
}

If all grid columns can be described using a single template, you have no need to create a column template selector. Instead, assign this template to the grid’s DataControlBase.ColumnGeneratorTemplate property.

When GridControl’s DataControlBase.AutoPopulateColumns property is set to true and the ColumnGeneratorTemplateSelector property is set to a custom DataTemplateSelector, the item parameter in the DataTemplateSelector.SelectTemplate method is of ColumnGeneratorItemContext type

To learn more, see Binding to a Collection of Columns.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnGeneratorTemplateSelector 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.

See Also