I think there are several possibilities.
One of them is using the SelectedItemBinding
property of the DataGridComboBoxColumn
.
It must point to the EquipmentMaker
property (I suppose your Equipment
class has an EquipmentMaker
property).
<DataGrid
ItemsSource="{Binding EquipmentMakers}" AutoGenerateColumns="False"
>
<DataGrid.Columns>
<!-- Other columns here -->
<DataGridComboBoxColumn Header="Equipment makers" SelectedItemBinding="{Binding EquipmentMaker}">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsDropDownOpen" Value="True" />
<Setter Property="ItemsSource"
Value="{Binding Path=DataContext.AllEquipmentMakers, RelativeSource={RelativeSource AncestorType={x:Type Window}},
UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="IsReadOnly" Value="True"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemsSource"
Value="{Binding Path=DataContext.AllEquipmentMakers, RelativeSource={RelativeSource AncestorType={x:Type Window}},
UpdateSourceTrigger=PropertyChanged, IsAsync=True}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
This example expects a view model with an Equipments
collection and a list AllEquipmentMakers
which holds all instances of EquipmentMaker
the user may choose in the combo box.
You may also check out this question. Here a SelectedValueBinding
is used.