title: C# Find the Selected State of all items in a ListBox
body: <p>I have found many examples on how to find the selected items in a listbox and how to iterate through a listbox;</p>
  
  <pre><code>for(int index=0;index &lt; listBox1.Items.Count; index++)
  {
      MessageBox.Show(listBox1.Items[index].ToString();
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>foreach (DataRowView item in listBox1.Items)
  {
     MessageBox.Show(item.Row["ID"].ToString() + " | " + item.Row["bus"].ToString());
  }
  </code></pre>
  
  <p>While these methods work great for the selected items, what I have yet to figure out, or find, is how to get the selected state, selected and unselected, of every item in a listbox, as the above only gives the selected. 
  Basically, I need something like this;</p>
  
  <pre><code>for(int index=0;index &lt; listBox1.Items.Count; index++)
  {
      if (index.SelectedMode == SelectedMode.Selected)
      {
          MessageBox.Show(listBox1.Items[index].ToString() +"= Selected";
      }
      else
      {
          MessageBox.Show(listBox1.Items[index].ToString() +"= Unselected";
      }
  }
  </code></pre>
  
  <p>I've found a snippet that said to use (listBox1.SelectedIndex = -1) to determine the selected state however I've not figured out or found how to build a loop around this to check each item in the listbox. </p>
  
  <p>I've also read that I should put the listbox items into an array, but again nothing about getting the selected state of each item in the listbox. </p>
  
  <p>I know I'll have to iterate through the listbox to accomplish what I'm needing, pretty sure it'll be one of the above loops, however I have yet to find how to extract the selected state of each item in the listbox. </p>
  
  <p>I'm using VS2013, C# Windows Form, .NET Framework 4.0
  Thanks in advance for any advice/direction.</p>