Adding different types in the same column in Sfdatagrid

How can add different types in the same column in SfDataGrid? For example, I want to have both comboboxes and normal textblocks in a single column. Is there any way to do that? Thanks in advance.

1 Reply

JG Jai Ganesh S Syncfusion Team June 22, 2016 01:52 PM UTC

Hi Aayush, 
 
You can achieve your requirement to load the different types in same column by using CellTemplateSelector like below, 
  
<Application.Resources> 
    <DataTemplate x:Key="CellTemplate1"> 
            <ComboBox Grid.Column="0" Height="35" Width="165"> 
                <ComboBoxItem>Sync1</ComboBoxItem> 
                <ComboBoxItem>Sync2</ComboBoxItem> 
                <ComboBoxItem>Sync3</ComboBoxItem> 
            </ComboBox> 
        </DataTemplate> 
 
    <DataTemplate x:Key="CellTemplate2"> 
        <TextBlock Foreground="DarkRed" Text="{Binding Path=Value}" /> 
    </DataTemplate> 
 </Application.Resources> 
 
 
<syncfusion:GridTemplateColumn MappingName="UserId" Width="300" SetCellBoundValue="True"  CellTemplateSelector="{StaticResource selector}"> 
                        
</syncfusion:GridTemplateColumn> 
 
 
public class EditTemplateSelector : DataTemplateSelector 
    { 
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) 
        { 
            if (item != null) 
            { 
                var data = (item as DataContextHelper).Record as UserInfo; 
 
                if (data.UserId < 1015) 
                    return Application.Current.Resources["CellTemplate1"] as DataTemplate; 
 
                else 
                    return Application.Current.Resources["CellTemplate2"] as DataTemplate; 
            } 
 
            return base.SelectTemplateCore(item, container); 
        } 
    } 
 
 
 
 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon