Remove all selected rows from an editable DataGridView

Remove all selected rows from an editable DataGridView.

There is small catch here. The new row is also selected but will trigger an exception when removed.

The following code will work correctly.

foreach (DataGridViewRow dr in list.SelectedRows)
{
   if (!dr.IsNewRow)
   {
      list.Rows.Remove(dr);
   }
}

Leave a Reply

Your email address will not be published. Required fields are marked *