I'm having trouble binding a WPF DataGridComboBoxColumn and setting the initial value. I can populate the combo box with the data from a collection but I can't seem to set the initial value.
<DataGridComboBoxColumn Header="Target Account Number"
ItemsSource="{Binding Account.RawAccountNumber}"
SelectedValueBinding="{Binding Account.RawAccountNumber, Mode=TwoWay}"
DisplayMemberPath="RawAccountNumber"
SelectedValuePath="RawAccountNumber">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Accounts}"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Accounts}"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
I've tried changing the ItemSource but this causes the combobox to be empty.
I've looked at several Stack Overflow posts but none of these have brought me to an answer yet. What can I try next?
Update
I intended to include my datagrid definition showing the Grid's ItemSource.
<DataGrid x:Name="dataGrid" DataGridCell.Selected="DataGrid_GotFocus" AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="10,51,0,0" VerticalAlignment="Top" Height="521" Width="862" ItemsSource="{Binding Transaction.Rows}">