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
280
TemplateField two way binding for combobox selected item
posted

I am using a combobox inside a template field, but when an item is selected, entity linked is not reflected about that. In the below snippet - SelectedFieldName is not set when ever we change anything in combobox

<dataPresenter:TemplateField Name="FieldName" AlternateBinding="{Binding SelectedFieldName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AlternateBindingRetentionMode="Retain"  Label="FieldName"  >
                                <dataPresenter:TemplateField.DisplayTemplate>
                                    <DataTemplate>
                                        <!--SelectedItem="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataPresenter:CellValuePresenter}}, Path=Record.DataItem.SelectedFieldName, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}"-->
                                        <ComboBox
                                            SelectedItem = "{editors:TemplateEditorValueBinding Mode=TwoWay}"
                                            ItemsSource="{Binding Source={StaticResource FieldValues}}"
                                          
                                    </DataTemplate>
                                </dataPresenter:TemplateField.DisplayTemplate>
                                <dataPresenter:TemplateField.EditTemplate>
                                    <DataTemplate>
                                        <ComboBox ItemsSource="{Binding Source={StaticResource FieldValues}}"
                                                  SelectedItem ="{editors:TemplateEditorValueBinding Mode=TwoWay}" />
                                    </DataTemplate>
                                </dataPresenter:TemplateField.EditTemplate>
                            </dataPresenter:TemplateField>

Parents
No Data
Reply
  • 280
    Verified Answer
    posted

    I got it working myself. Changed

    <dataPresenter:TemplateField Name="FieldName" BindingType="Unbound"  Label="FieldName"  >
                                    <dataPresenter:TemplateField.DisplayTemplate>
                                        <DataTemplate>
                                           
                                            <ComboBox 
                                                SelectedItem="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataPresenter:CellValuePresenter}}, Path=Record.DataItem.SelectedFieldName, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}"
                                                ItemsSource="{Binding Source={StaticResource FieldValues}}" />
                                              
                                        </DataTemplate>
                                    </dataPresenter:TemplateField.DisplayTemplate>
                                    <dataPresenter:TemplateField.EditTemplate>
                                        <DataTemplate>
                                            <ComboBox ItemsSource="{Binding Source={StaticResource FieldValues}}"
                                                      SelectedItem ="{editors:TemplateEditorValueBinding Mode=TwoWay}" />
                                        </DataTemplate>
                                    </dataPresenter:TemplateField.EditTemplate>
                                </dataPresenter:TemplateField>

                                          

Children