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

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.v19.1.Core.dll

Declaration

public DataTemplate CellTemplate { get; set; }
Public Property CellTemplate As DataTemplate

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 EditGridCellData class.

The EditGridCellData class has the Value property that provides access to the cell editable value. Use the RowData.Row property to access a row's data object property: {Binding RowData.Row.[YourPropertyName]}

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>
public ObservableCollection<CountryCities> Items {
    get {
        if(this._Items == null) {
            this._Items = new ObservableCollection<CountryCities>();

            CountryCities usa = new CountryCities() {
                Country = "USA",
                Cities = new List<string> { "Washington, D.C.", "New York", "Los Angeles", "Las Vegas" },
                City = "Los Angeles"
            };
            this._Items.Add(usa);

            CountryCities germany = new CountryCities() {
                Country = "Germany",
                Cities = new List<string> { "Berlin", "Munich", "Frankfurt" },
                City = "Munich"
            };
            this._Items.Add(germany);

            CountryCities russia = new CountryCities() {
                Country = "Russia",
                Cities = new List<string> { "Moscow", "Saint-Petersburg" },
                City = "Moscow"
            };
            this._Items.Add(russia);
        }
        return this._Items;
    }
} 
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.

See Also