title: Remove a row from a DataTable within a DataSet
body: <p>I have a DataSet with several DataTables inside. I'm displaying the DataTables in a ListView (I didn't know about databinding when I wrote the code). Anyway, I would like to remove rows from the DataTables inside the DataSet.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>foreach (DataRow row in dsData.Tables["Table1"].Rows)
    {
       //find the row that contains the username I'm after
       if (item.SubItems[2].Text == row["LoginName"].ToString())            
         {
           dsData.Tables["Table1"].Rows.Remove(row); //&lt;- main code of interest
         }
    }
  </code></pre>
  
  <p>I've also tried </p>
  
  <pre><code>dsData.Tables["Table1".Rows.Delete(row);
  </code></pre>
  
  <p>The problem I'm experiencing is that the when you remove a row I get the exception:</p>
  
  <p><strong>Collection was modified; enumeration operation might not execute.</strong></p>
  
  <p>From what I understand it's because when you remove a row from a ListView the row below it moves up and causes all this trouble. The code itself does what it's supposed to but it's not nice to see that exception when when you run it. </p>
  
  <p>I was about to rewrite the whole class with a DataGridView but would rather correct that single line if possible :).</p>
  
  <p>EDIT: I'm not even sure a DataGridView would solve the problem anyway.</p>