This is a migrated thread and some comments may be shown as answers.

Edit lookup values with DataFormComboBoxField

2 Answers 119 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Benoit
Top achievements
Rank 1
Benoit asked on 11 May 2016, 08:25 AM
Hello,
Reading http://docs.telerik.com/devtools/wpf/controls/raddataform/how-to/raddatafor-edit-lookup-values-with-radcombobox.html
I have a viewmodel with (simplified):
Agent
    - long Id
    - string FirstName
    - Team Team
Team
   - long Id
   - string Name

In an UserControl (simplified):
<UserControl.Resources>
        <viewmodels:EscortViewModel x:Key="EscortViewModel" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" DataContext="{StaticResource EscortViewModel}">
<Grid.Resources>
            <DataTemplate x:Key="AgentEditTemplate">
                    <telerik:DataFormDataField Label="Last Name" DataMemberBinding="{Binding LastName, Mode=TwoWay}" Grid.Row="0" Grid.Column="1"/>
                    <telerik:DataFormComboBoxField Label="Team"
                                                   SelectedValuePath="Id"
                                                   DisplayMemberPath="Name"
                                                   Grid.Row="2" Grid.Column="1"
                                                   DataMemberBinding="{Binding Team.Id, Mode=TwoWay}"
                                                   ItemsSource="{Binding Teams, Source={StaticResource EscortViewModel}}"
                                                   />
                </Grid>
            </DataTemplate>
</Grid.Resources>
        <StackPanel>
            <telerik:RadGridView x:Name="agentViewer"
                                    ItemsSource="{Binding Agents}"
                                    AutoGenerateColumns="False"
                                    RowIndicatorVisibility="Collapsed"
                                    IsReadOnly="True"
                                    >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewToggleRowDetailsColumn />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName, Mode=OneWay}" Header="Name" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Team.Name, Mode=OneWay}" Header="Team" />
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.RowDetailsTemplate>
                    <DataTemplate>
                        <Grid Background="DarkGray">
                        <Grid Margin="15">
                            <telerik:RadDataForm x:Name="agentDataEdit"
                                                    CurrentItem="{Binding}"
                                                    Header="Edit agent:"
                                                    AutoGenerateFields="False"
                                                    EditTemplate="{StaticResource AgentEditTemplate}"
                                                    ReadOnlyTemplate="{StaticResource AgentEditTemplate}"
                                                    NewItemTemplate="{StaticResource AgentEditTemplate}"
                                                    >
                                </telerik:RadDataForm>
                        </Grid>
                        </Grid>
                    </DataTemplate>
                </telerik:RadGridView.RowDetailsTemplate>
            </telerik:RadGridView>
                <Grid Background="DarkGray" x:Name="panelAddNew">
                    <Grid Margin="15">
                        <telerik:RadDataForm x:Name="agentDataNew"
                                                    Header="Add agent:"
                                                    AutoGenerateFields="False"
                                                    EditTemplate="{StaticResource AgentEditTemplate}"
                                                    ReadOnlyTemplate="{StaticResource AgentEditTemplate}"
                                                    NewItemTemplate="{StaticResource AgentEditTemplate}"
                                                    ItemsSource="{Binding Agents}"
                                                    >
                        </telerik:RadDataForm>
                    </Grid>
                </Grid>
        </StackPanel>
</Grid>

Almost everything works great. In the complete form, i can edit string, long and enum (with DataFormComboBoxField). What i can't do is the binding with the Agent.Team.Id.
In fact, the value from DB is displayed (team "A" or "B"...) but when i edit the form and change the Team (list displayed in the DataFormComboBoxField), it never return in the set of the Agent.Team property.
Am I missing something or did i do something wrong ? Is there a bug or an other syntax for the DataMemberBinding="{Binding Team.Id, Mode=TwoWay}" ?
I would like to not use an Agent.TeamId property but the object please.
Thank you very much.

2 Answers, 1 is accepted

Sort by
0
Benoit
Top achievements
Rank 1
answered on 11 May 2016, 03:25 PM

More informations:

I have the same issue with the GridViewComboBoxColumn in a RadGridView.

Either i get the problem i first came for, either i have this one (with a GridViewComboBoxColumn or a DataFormComboBoxField):

                <telerik:GridViewComboBoxColumn Header="Retour 2"
                                                   DisplayMemberPath="Name"
                                                   DataMemberBinding="{Binding Team, Mode=TwoWay}"
                                                   ItemsSource="{Binding Paths, Source={StaticResource EscortViewModel}}"
                                                   />

With that, when i load the usercontrol, the value is not set/displayed in the column... BUT, when i change it, it calls the set of the viewmodel and update the ViewModel (so the displayed values).

What i can't find is how mix the two to display the data when the usercontrol is loaded AND update the value !

Thank you very much

0
Stefan
Telerik team
answered on 13 May 2016, 01:29 PM
Hello Benoit,

Can you please check out the ComboBox Column help topic, as the proper definition of GridViewComboBoxColumn is demonstrated in it? Basically, the DataMemberBinding should relate to the SelectValueMemberPath.

I have also attached a sample application demonstrating how the DataFormComboBoxField should be bound to an object. Please take a look at the Player class. Instead of binding the DataMemberBinding to its ClubID property, a nested property binding is used.

Hope this helps.

Best Regards,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
DataForm
Asked by
Benoit
Top achievements
Rank 1
Answers by
Benoit
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or