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

Bind different sources to SfTreeGrid's templated cells

Thread ID:

Created:

Updated:

Platform:

Replies:

129329 Mar 13,2017 04:47 PM UTC Mar 14,2017 01:40 PM UTC WPF 1
loading
Tags: SfTreeGrid
Ivailo J
Asked On March 13, 2017 04:47 PM UTC

Hello,
I'm trying to use SfTreeGrid to display "Tests" and "Profiles" (the profiles contains other tests). I have two columns Name and Result, and templates (textboxTemplate and comboboxTemplate) to customize result's cell. Some of the tests have a text result, but others needs combobox to select an option. Each combobox shoud contains different options depending on the test. Could you please give me a hint how can I fill ItemSources of the comboboxes? Is it possible to do that with SfTreeGrid or I need another control?
Thanks for your help.

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 14, 2017 01:40 PM UTC

Hi Ivailo, 

Thank you for contacting Syncfusion support. 

We have analyzed your query. You can bind the different ItemsSources to each row of the ComboBox by using GridTemplateColumn in the SfTreeGrid as like below code snippet. 

Code Snippet:  

<syncfusion:TreeGridTemplateColumn HeaderText="ShipCity"  MappingName="CityId" syncfusion:FocusManagerHelper.WantsKeyInput="True"> 
    <syncfusion:TreeGridTemplateColumn.CellTemplate> 
        <DataTemplate> 
            <TextBlock Text="{Binding CityId}" HorizontalAlignment="Right" /> 
        </DataTemplate> 
    </syncfusion:TreeGridTemplateColumn.CellTemplate> 
 
    <syncfusion:TreeGridTemplateColumn.EditTemplate> 
        <DataTemplate> 
            <ComboBox ItemsSource="{Binding CityDescription, Converter={StaticResource converter}}"  
                    SelectedItem="{Binding CityId,Mode=TwoWay}"/> 
        </DataTemplate> 
    </syncfusion:TreeGridTemplateColumn.EditTemplate> 
</syncfusion:TreeGridTemplateColumn> 


The ItemsSource for each row of the ComboBox is set based on the CityDescription with the help of converter as below code, 

public class ItemsSourceConverter:IValueConverter 
{ 
    ShipCityDetailsRepository ShipCity = new ShipCityDetailsRepository(); 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
        string[] shipcities=null; 
        //Check whether the  CityName contains  which is received from value parameter 
        if (ShipCity.ContainsKey(value.ToString())) 
        { 
            //if the key matched , it will return the corresponding shipcities  
            ShipCity.TryGetValue(value.ToString(), out shipcities); 
            return shipcities; 
        }            
        return null; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
        throw new NotImplementedException(); 
    } 
} 


Please let us know if you have any query. 

Regards, 
Muthukumar K 


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

;