title: Getting DataGridView rows shifting code working?
body: <p>Can someone help me fix this piece of code I found?
  It's suppose to shift a whole row up on a winform datagridview.</p>
  
  <p>It works like it's supposed to except for the fact that the old row position stays selected when there is only 1 selected item shifted.</p>
  
  <pre><code>DataGridViewSelectedRowCollection selectedRows = dataGridView.SelectedRows;
  dataGridView.ClearSelection();  //this does not work.
  for (int i = 0; i &lt;= selectedRows.Count - 1; i++)
  {
      int selRowIndex = selectedRows[i].Index;
      if (selRowIndex &gt; 0)
      {
          dataGridView.Rows.Remove(selectedRows[i]);
          dataGridView.Rows.Insert(selRowIndex - 1, selectedRows[i]);
          dataGridView.Rows[selRowIndex - 1].Selected = true; 
      }
  }
  </code></pre>