Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
138253
How can I place different editors in one field based on the data in the particular row they are placed in XamDataGrid?
posted

Let look at the following scenario: We have a questions and answers and we want to display this in the XamDataGrid. Based on the specific question we want the cell for the field “Answer” to contain different types of data. For example if the question is something like “What is your birth date?” the answer cell to provide DatePicker and if the question is “What is your name?” the Answer to be edited as string.  

In order to achieve such functionality we can convert the template for the “Answer” field using IValueConverter based on the number of the question:

 

                    <igDP:Field Name="Answer" >

                        <igDP:Field.Settings>

                            <igDP:FieldSettings >

                                <igDP:FieldSettings.CellValuePresenterStyle>

                                    <Style TargetType="{x:Type igDP:CellValuePresenter}" >

                                        <Setter Property="ContentTemplate" Value="{Binding Path=DataItem.Question, Converter={StaticResource converter}}"/>

                                      </Style>

                                </igDP:FieldSettings.CellValuePresenterStyle>

                            </igDP:FieldSettings>

                        </igDP:Field.Settings>

                    </igDP:Field>

 

We can create different DataTemplaes based on the editor we want to put in the cell and to bind its value to the one that is provided by the DataSource. Also in order to preserve the background colors for this filed we can bind the background property of the editor to its CellValuePresenter background. For example the following code demonstrates how we can create a new template for date time data :

       <Style TargetType="{x:Type igEditors:XamDateTimeEditor}">

            <Style.Triggers>

                <Trigger Property="IsInEditMode" Value="False">

                    <Setter  Property="Background"  Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Background}" />

                </Trigger>

            </Style.Triggers>

        </Style>

 

        <DataTemplate x:Key="dateTimeTemplate">

           

            <igEditors:XamDateTimeEditor BorderBrush="Transparent"

                                         IsInEditMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=IsInEditMode}" 

                                         Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value}" >

               

            </igEditors:XamDateTimeEditor>

        </DataTemplate>

DifrentEditorsInField.zip