Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get all information from custom ListView with two different bindings?
    primarykey
    data
    text
    <p>I'm currently working on a <strong>"Tournament Generator"</strong> and in one step I need to associate a trainer to a team. Therefore I used a <strong>WPF ListView</strong> with integrated Comboboxes. Selection Mode is <strong>"Multiple"</strong> Here's a picture :</p> <p>Well no picture because of no reputation.</p> <p><strong>It looks like this:</strong></p> <p>It has two columns. The first columns hold different trainer names. The second column holds in each line a combobox with different teams. For each trainer a team can be selected in the combobox.</p> <p><strong>And here's the code:</strong></p> <pre><code> &lt;ListView x:Name="TrainerListView" ItemsSource="{Binding Trainer}" HorizontalAlignment="Left" VerticalAlignment="Top" SelectionMode="Multiple"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Trainer" Width="150"/&gt; &lt;GridViewColumn Header="Team" Width="150"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},Path=DataContext.Teams}" Width="120" DisplayMemberPath="Name"/&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; </code></pre> <p>As you can see from the code the ListView has the Trainer property as ItemsSource and the ComboBoxes the Teams property.</p> <p>After clicking a button, I want to get all the selected values. Here: "David with FC Liverpool", "Bernd with Borussia Dortmund" and "Tim with Bayern Munic". I tried the following:</p> <pre><code>private void StartTournamentButton_Click(object sender, RoutedEventArgs e) { var selectedItems = TrainerListView.SelectedItems; } </code></pre> <p>But the selectedItems variable only holds the selected trainer objects "David, Bernd and Tim".</p> <p>Still I couldn't find a way to retrieve the "Teams values" from the ListView, not to mention an association of Trainer and Team. How do I get the values of the selected rows? Best as associated values. </p> <p>best regards,</p> <p>David</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload