I have a DataTemplate for a ComboBox in a GridView column. I want to display a ComboBox when the cell is being edited and a TextBlock otherwise. However I am having trouble getting the TextBox to display the desired value.
The ViewModel for the row has only RegionId but the Combo is bound to a collection of Region objects (with Id and Name). I'd like to display the Region.Name when the value is not being edited, at the moment I can only find a way to show the RegionId because the ViewModel does not contain a Name property.
I am using a Telerik combobox but I think my problem would be the same with a standard ComboBox control as I think this is just a binding issue.
How should I bind my TextBlock in the DataTemplate?
<telerik:GridViewDataColumn>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RegionId}" /> <!-- would like Region.Name -->
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadComboBox ItemsSource="{Binding Source={StaticResource regionView}}"
DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding Path=RegionId, Mode=TwoWay}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>