I'm having trouble reading the selecteditem value of a combobox element which is part of a datagrid element. I suspect thre is a problem with the binding. With "$WPFDataGrid.SelectedItems.combobox" I get all values but not the selecteditem value of the combobox.
<DataGrid.Columns>
<DataGridTemplateColumn Header="Combobox" Visibility="Visible" Width="300">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding Path=Combobox}"
SelectedItem="{Binding Path=Result, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
class myRow{
[Array]$Combobox
[string]$Hostname
}
$test1 = New-Object myRow -Property @{Hostname = "test1"; Combobox = "TEST1","TEST2" }
$WPFDataGrid.ItemsSource = @($test1)
Full Code:Full Code @GitHub
I was able to find the solution: In the XAML area the binding path had to be changed from ' SelectedItem="{Binding Path=Result' to ' SelectedItem="{Binding Path=Combobox'.
SelectedItem="{Binding Path=Combobox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">