I have a ComboBox defined in a DataGrid as shown. The ItemsSource
of the ComboBox is a List of the custom class CodePickList
containing Name
and ID
properties. The DisplayMemberPath
is the Name
property and the SelectedValuePath
is the ID
property. The SelectedValue
is bound to the GLCode
property on the DataGrid ItemsSource
. (Note that the ItemsSource
of the DataGrid is a view.) The ComboBox populates properly and the binding of the ComboBox selection to the GLCode
property works as well. All fine and good for new data. The problem is with the existing data in the ItemsSource
of the DataGrid. The textblock of the ComboBox is simply blank. Apparently the ComboBox is unable to match the GLCode
property on the DataGrid ItemsSource
with the ID
property on the ComboBox ItemsSource
when the ComboBox ItemsSource loads. These properties are of the same type. WinForms handles this scenario but I can't get it to work in WPF.
<DataGrid ItemsSource="{Binding EntityDetailsView.View}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{BindingPath=DataContext.CodePickList, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
DisplayMemberPath="Name" SelectedValuePath="ID" SelectedValue="{Binding GLCode, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEditable="False" IsReadOnly="False"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>