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.
Unfortunately, activation email could not send to your email. Please try again.

Finding Column ID from GridCell in DataTemplateSelector

Thread ID:

Created:

Updated:

Platform:

Replies:

123673 Apr 8,2016 02:51 PM Apr 11,2016 03:29 AM UWP 1
loading
Tags: SfDataGrid
Deanna Delapasse
Asked On April 8, 2016 02:51 PM


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 03:29 AM

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

Regards,
Jayapradha


CONFIRMATION

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.

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.

;