A newer version of this page is available. Switch to the current version.

ColumnBase.CellTemplateSelector Property

Gets or sets an object that chooses a cell template based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

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


public DataTemplateSelector CellTemplateSelector { get; set; }
Public Property CellTemplateSelector As DataTemplateSelector

Property Value

Type Description

A DataTemplateSelector descendant that chooses a template based on custom logic.



A template that defines the presentation of data cells is specified by the ColumnBase.CellTemplate property. If you have more than one template that can be used to render cells, you can implement custom logic to choose the required template. To do this, derive from the DataTemplateSelector class, implement the SelectTemplate method that returns a template which meets the required condition, and assign it to the CellTemplateSelector property.

If both the ColumnBase.CellTemplate and CellTemplateSelector are specified, a cell is rendered using the template returned by the template selector. If the template selector returns null, the template specified by the ColumnBase.CellTemplate property is used.

This sample illustrates how to change a cell template based on a condition using the CellTemplateSelector.

To implement this approach, do the following:

  1. Implement custom DataTemplates. Editors declared in these templates should follow our recommendations from this help topic: ColumnBase.CellTemplate:

        <DataTemplate x:Key="booleanEditor">
            <dxe:CheckEdit Name="PART_Editor" />
        <DataTemplate x:Key="buttonEditor">
            <dxe:ButtonEdit Name="PART_Editor" />
        <DataTemplate x:Key="comboboxEditor">
            <dxe:ComboBoxEdit Name="PART_Editor">
        <DataTemplate x:Key="dateEditor">
            <dxe:DateEdit Name="PART_Editor" />
        <DataTemplate x:Key="textEditor">
            <dxe:TextEdit Name="PART_Editor" />
    <dxg:GridControl Name="grid">
            <dxg:GridColumn FieldName="Editor" />
            <dxg:GridColumn FieldName="Value">
                    <local:EditorTemplateSelector />
            <dxg:TableView Name="view" AutoWidth="True" EditorButtonShowMode="ShowAlways" />
  2. Create a custom DataTemplateSelector descendant. This descendant should return templates according to your scenario requirements.


    Each GridControl cell contains an object of the EditGridCellData data type in its DataContext. This object's RowData.Row property contains your data item. You can use this property if your logic should take property values from data items into account:

    public class EditorTemplateSelector : DataTemplateSelector {
        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            GridCellData data = (GridCellData)item;
            var dataItem = data.RowData.Row as TestData;
            return string.IsNullOrEmpty(dataItem.Editor) ? null : (DataTemplate)((FrameworkElement)container).FindResource(dataItem.Editor);
See Also