 <p>Be familiar with using a debugger, you will be able to find out where the issue is.</p> <p>You are clearing the selection in your loop</p> <pre><code>foreach (DataGridViewRow row in dataGridView1.Rows) { } </code></pre> <p>Rethink the if-else logic in it and you will see why. You are clearing your previous selections when you are not suppose to.</p>