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

ColumnBase.CellTemplate Property

Gets or sets the template that defines the presentation of column cells. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

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

Declaration

public DataTemplate CellTemplate { get; set; }

Property Value

Type Description
DataTemplate

A DataTemplate object that defines the presentation of column cells.

Remarks

Use the CellTemplate property to define a template that specifies the visualization of column cells. The binding source for the CellTemplate template is represented by the GridCellData class.

The code sample belows shows how to use a custom ComboBoxEdit within grid cells:

<dxg:GridControl AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" ItemsSource="{Binding Items}">
    <dxg:GridColumn FieldName="Country"/>
    <dxg:GridColumn FieldName="City">
        <dxg:GridColumn.CellTemplate>
            <DataTemplate>
                <dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding RowData.Row.Cities}"/>
            </DataTemplate>
        </dxg:GridColumn.CellTemplate>
    </dxg:GridColumn>
    <dxg:GridControl.View>
        <dxg:TableView/>
    </dxg:GridControl.View>
</dxg:GridControl>

Tip

Tip

A template that defines the presentation of data cells is specified by the 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 ColumnBase.CellTemplateSelector property.

If both the CellTemplate and ColumnBase.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 CellTemplate property is used.

Note

When using the CellTemplate, an editor specified with the ColumnBase.EditSettings property is ignored (but its formatting settings persist).

Note

Editors specified in the CellTemplate do not affect data processing (sorting, grouping, filtering, summary calculation) and export.

Use the PrintCellStyle property to customize cell appearance when printing and exporting the GridControl‘s data.

The GridControl.CustomColumnDisplayText allows you to display custom text within any cell. The provided text provided is used when the grid is printed.

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