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.
Syncfusion Feedback

Adding different types in the same column in Sfdatagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

124665 Jun 21,2016 01:18 PM UTC Jun 22,2016 01:52 PM UTC UWP 1
loading
Tags: SfDataGrid
Aayush Gupta
Asked On June 21, 2016 01:18 PM UTC

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.

Jai Ganesh S [Syncfusion]
Replied On 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 


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.

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

;