title: How can I loop through a ListBox's selected items in Compact Framework?
body: <p>I adapted the following code from <a href="https://social.msdn.microsoft.com/Forums/windows/en-US/96df2c84-3507-4322-a441-4c3ba2a6522b/how-to-get-multiple-selected-values-and-items-from-listbox-?forum=winforms" rel="nofollow">here</a></p>
  
  <pre><code>foreach (String table in tablesToTouch)
  {
      foreach (Object selecteditem in listBoxSitesWithFetchedData.SelectedItems)
      {
          site = selecteditem as String;
          hhsdbutils.DeleteSiteRecordsFromTable(site, table);
      }
  }
  </code></pre>
  
  <p>...but, alas, the SelectedItems member appears unavailable to me: "<em>'System.Windows.Forms.ListBox' does not contain a definition for 'SelectedItems' and no extension method 'SelectedItems' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?)</em>"</p>
  
  <p>Another suggestion was:</p>
  
  <pre><code>foreach(ListItem listItem in listBox1.Items)
  {
     if (listItem.Selected == True)
     {
       . . .
  </code></pre>
  
  <p>...but I also don't have ListItem available.</p>
  
  <p>What is a workaround to accomplish the same thing?</p>
  
  <h2>UPDATE</h2>
  
  <p>There are at least two (somewhat kludgy) things I could do: </p>
  
  <pre><code>0) Manually keep track of items selected in listBoxSitesWithFetchedData (as they are clicked) and loop through *that* list
  1) Dynamically create checkboxes instead of adding items to the ListBox (getting rid of the ListBox altogether), and use the text value of checked checkboxes to pass to the "Delete" method
  </code></pre>
  
  <p>But I'm still thinking there's got to be a more straightforward way than those.</p>
  
  <h2>UPDATE 2</h2>
  
  <p>I can do this (it compiles):</p>
  
  <pre><code>foreach (var item in listBoxSitesWithFetchedData.Items)
  {
      hhsdbutils.DeleteSiteRecordsFromTable(item.ToString(), table);
  }
  </code></pre>
  
  <p>...but I'm still left with the problem of only acting on the items that have been selected.</p>
  
  <h2>UPDATE 3</h2>
  
  <p>Since the CF-Whisperer said that listbox multiselection isn't possible in the murky and misty labyrinthine world of CF (cuneiform forms), I simplified the code to:</p>
  
  <pre><code>foreach (String table in tablesToTouch)
  {
      // Comment from the steamed coder:
      // The esteemed user will have to perform this operation multiple times if they want 
  to delete from multiple sites              
      hhsdbutils.DeleteSiteRecordsFromTable(listBoxSitesWithFetchedData.SelectedItem.ToString(), 
          table);
  }
  </code></pre>