Bind GridTemplateColumn to ItemsSouce items property

Hello, i am having problem getting the property of a dynamically created TemplateColumn, with a property of the Itemssources property. Particularly

i have a class like this

 public class InsertPersonShowDetails
    {
        public string Parameter { get; set; }

        public string ParameterType { get; set; }        

        public string ParameterValue { get; set; }
        
    }

and the SfDatagrid ItemsSource is Bound to a ViewModels Observable collection of type InsertPersonShowDetails.
In the datagrid, i am using triggers to create TemplateColumn based on the value of ParameterType property. It creates either a textbox ,or a comboboxn which works fine.
The problem is i can't bind the textbox ,or the combobox inside the TemplateColumn, with the property ParameterValue of my Itemssource.

this is my XAML SfDataGrid

<syncfusion:SfDataGrid x:Name="InsertPersonGeneralDatagrid" AutoGenerateColumns="False" MinHeight="500" MinWidth="500" ColumnSizer="Star" ItemsSource="{Binding Gd,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Floko1}">
                                <syncfusion:SfDataGrid.Columns>
                                    <syncfusion:GridTextColumn HeaderText="ParameterName" MappingName="Parameter">
                                        
                                    </syncfusion:GridTextColumn>
                                    <syncfusion:GridTemplateColumn HeaderText="ParamValue" MappingName="ParameterValue">
                                        <syncfusion:GridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <ContentControl>
                                                    <ContentControl.Style>
                                                        <Style TargetType="ContentControl">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding ParameterType}" Value="sample1">
                                                                    <Setter Property="ContentTemplate">
                                                                        <Setter.Value>
                                                                            <DataTemplate>
                                                                                <TextBox >        
                                                                                    
                                                                                </TextBox>
                                                                            </DataTemplate>
                                                                        </Setter.Value>                                                                        
                                                                    </Setter>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding ParameterType}" Value="sample2">
                                                                    <Setter Property="ContentTemplate">
                                                                        <Setter.Value>
                                                                            <DataTemplate>
                                                                                <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type                                                                                                               syncfusion:SfDataGrid}}, Path=DataContext.Floko}" DisplayMemberPath="Name"/>
                                                                            </DataTemplate>
                                                                        </Setter.Value>
                                                                    </Setter>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </ContentControl.Style>
                                                </ContentControl>
                                            </DataTemplate>
                                        </syncfusion:GridTemplateColumn.CellTemplate>                                        
                                    </syncfusion:GridTemplateColumn>                                    
                                </syncfusion:SfDataGrid.Columns>
                            </syncfusion:SfDataGrid>


Any Help is much appreciated.


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team May 6, 2021 02:54 PM UTC

Hi Alexis,

Thank you for contacting Syncfusion Support.

Based on provided information we suspect that GridTemplateColumn display TextBox and ComboBox based on data values of any one field contains in ItemSource binded in SfDataGrid. So, we have prepared the sample for achieve your requirement.
 
For more information, please refer the below UG link,

UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#sets-edittemplate-based-on-custom-logic
 
https://www.syncfusion.com/kb/4896/how-to-bind-different-itemssources-to-each-row-of-the-combobox-by-using-gridtemplatecolumn

We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S
 


Marked as answer
Loader.
Up arrow icon