Reputation: 159
I want to find out how to get the selected value from a combobox column in a listview with a gridview view or even a datagrid.
The xaml will look like this:
<ListView Name="lstPicker" ItemsSource="{Binding}" SelectionMode="Single" Margin="6" >
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView x:Name="gridParams" ColumnHeaderContainerStyle="{StaticResource DialogueGridViewColumnHeader}" >
<GridViewColumn Header="Workflow Parameters" Width="Auto" DisplayMemberBinding="{Binding WorkflowParameterName}" />
<GridViewColumn Header="Profile Parameters" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=ProfileParametersList}" DisplayMemberPath="ProfileParameterName" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
What I want to do is to save for each workflow parameter in the list a value from the profiles parameter combobox.
The list is binded to an Observable Collection with some workflow parameters that contains another Observable Collection named ProfileParametersList that contains some parameter profiles. So for each item in the mother collection i want a detail to be picked from the child Collection and handled afterwards.
I tried to get the rows and cast them to the Class type that i use but i am unable to see what was selected in the combobox as the whole DetailsList is there. Any help is apreciated
The datagrid version can look like this:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Name="dgPicker" CanUserAddRows="False" CanUserDeleteRows="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Workflow Parameters" Binding="{Binding WorkflowParameterName}" IsReadOnly="True" />
<DataGridTemplateColumn Header="Profile Parameters">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding ProfileParametersList}" DisplayMemberPath="ProfileParameterName" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Upvotes: 1
Views: 1645
Reputation: 81243
Create a property SelectedProfileParameter
in your class WorkFlowParameter
and bind it to the SelectedItem of your combobox. This should work for you then -
<DataGridTemplateColumn Header="Profile Parameters">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding ProfileParametersList}" DisplayMemberPath="ProfileParameterName" SelectedItem="{Binding SelectedProfileParameter}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Upvotes: 1