title: Looping through all items in ListBox?
body: <p>I have a list box which is populated by this code:</p>
  
  <ul>
  <li>lstOutcome.Items.Add(lstMap.SelectedItem.Text);</li>
  </ul>
  
  <p>In the listbox lstOutcome, I need to be able to loop through
  the listbox and be able to take the value of the
  first,second, etc, list items.</p>
  
  <p>The reason I need to loop through each line and grab the
  value of that line is so I can use whatever value was in
  that line for populating something else.</p>
  
  <p>For example, in my list box I have:</p>
  
  <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  </ul>
  
  <p>I need to be able to loop through the listbox on button
  click and have the values assigned to txtboxes:</p>
  
  <ul>
  <li>textbox1.Text = 'item 1 in the listbox';</li>
  <li>textbox2.Text = 'item 2 in the listbox';</li>
  <li>textbox3.Text = 'item 3 in the listbox';</li>
  </ul>
  
  <p>I am not sure if I need an array or how this can be
  accomplished. The point of this example is that I will
  actually be using the items in the listbox to map columns. I
  am importing an Microsoft Excel spreadsheet. In lstMap I have the
  column names and I am trying to get the column names to match
  my database. Using this code I am trying to take the values
  of the listbox:</p>
  
  <pre><code>foreach(object li in lstOutcome.Items)
  {
      bulkCopy.DestinationTableName = "Customers";
      //Amount to bulkcopy at once to prevent slowing with large imports.
      bulkCopy.BatchSize = 200;
      SqlBulkCopyColumnMapping map1 = new SqlBulkCopyColumnMapping(li.ToString(), "CustomerID");
      bulkCopy.ColumnMappings.Add(map1);
  </code></pre>