title: C# WPF - Get the selected items from a ListView
body: <p>I have a listview with multiple columns. The data are binding with a DataView. The first column is the ID, the second column is the name.</p>
  
  <p>When one item is selected on my listview named lstInterrogateur, i get the ID like that:</p>
  
  <pre><code>DataRowView CompRow;
  string InsertQuery = "INSERT INTO interrogateur_matiere (idinterrogateur_matiere, idMatiere, idInterrogateur) VALUES ";
  int SComp, i=1, total;
  long idInterrogateur, idMatiere;
  
  SComp = lstInterrogateur.SelectedIndex;
  CompRow = lstInterrogateur.Items.GetItemAt(SComp) as DataRowView;
  idInterrogateur = Convert.ToInt16(CompRow["idInterrogateur"]);
  </code></pre>
  
  <p>And when multiple items are selected on my listview named lstMatiereInterrogateur, i get the ID like that:</p>
  
  <pre><code>total = lstMatiereInterrogateur.SelectedItems.Count;
  
  foreach (var item in lstMatiereInterrogateur.SelectedItems)
  {                    
     SComp = lstMatiereInterrogateur.SelectedIndex;
     CompRow = lstMatiereInterrogateur.Items.GetItemAt(SComp) as DataRowView;
     idMatiere = Convert.ToInt16(CompRow["idMatiere"]);
     InsertQuery += "(NULL, '" + idInterrogateur + "', '" + idMatiere + "')";
     if (total != i)
         InsertQuery += ", ";
         i++;
     }
  }
  </code></pre>
  
  <p>But then i only get the last ID. For exemple, i selected 2 items ID=3 et ID=5, i will get 2 times ID=5. Why?</p>
  
  <p>Thanks.</p>