We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Finding Column ID from GridCell in DataTemplateSelector

Thread ID:





123673 Apr 8,2016 06:51 PM UTC Apr 11,2016 07:29 AM UTC UWP 1
Tags: SfDataGrid
Deanna Delapasse
Asked On April 8, 2016 06:51 PM UTC

Sorry for asking so many questions, but I'm trying to make sure this Grid will work for us before we spend the money to purchase it!

I've set up a DataTemplateSelector for my columns and when I receive the callback in my  protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) I can not figure out how to figure out the current column.
The first parameter is my bound object and  second parameter (container) is a GridCell, but the ColumnBase field is null.  Is there some other way I can get the column name?   

Code that creates the column and connects the selector

    GridTextColumn gtc = new GridTextColumn()
        HeaderText = "Code Template",
        MappingName = "positionCode",
        CellTemplateSelector = templateSelector,
        SetCellBoundValue = true,                            

Callback for template selection:
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)

Jayapradha S [Syncfusion]
Replied On April 11, 2016 07:29 AM UTC

Hi Deanna,

Thank you for contacting Syncfusion Support.

We have analyzed your query.  You are getting the null item  in Container’s columnbase at first time in SelectTemplateCore since DataTemplateSelector is invoked before the content property has been initialized. You can get the column name from Container object in SelectTemplateCore when content has been initialized. Please refer the below code and sample,

Code Example:

public class CellTemplateSelectorExt:DataTemplateSelector


        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)


            if ((container as GridCell).ColumnBase != null)


                Debug.WriteLine((container as GridCell).ColumnBase.GridColumn.MappingName);

                return App.Current.Resources["cellTemplate"] as DataTemplate;


            return base.SelectTemplateCore(item, container);


Sample: http://www.syncfusion.com/downloads/support/forum/123673/ze/SfDataGrid_CellTemplateSelector1192384304



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon