title: Listbox Selected Item to array
body: <p>I have a DataTable with 2 columns called "ID" and "Software" that I have used as a DataSource for a lst_Software multiselect listbox.  </p>
  
  <p>I'm trying to gather the ID for all the selected items in that have been selected and place that in an int[] array.</p>
  
  <p><strong>Listbox setup:</strong></p>
  
  <pre><code>lst_Software.DataSource = software;  //software is a DataTable
  lst_Software.DisplayMember = "Software";
  lst_Software.ValueMember = "ID";    
  </code></pre>
  
  <p><strong>I've tried below</strong></p>
  
  <pre><code>List&lt;int&gt; list = new List&lt;int&gt;();
  for (int i = 0; i &lt; lst_Software.SelectedItems.Count; i++)
  {
      list.Add(Convert.ToInt32(lst_Software.SelectedValue.ToString()));
  }
  int[] software = list.ToArray();
  </code></pre>
  
  <p>I'm finding that I'm only getting the first selected value except it will not iterate through all...  I know why though.  I'm not using <strong>i</strong> to get passed through inside the for loop. I'm hoping someone can give me a direction to go to iterate through all the selected values.</p>
  
  <p>Thank you</p>