Tag Archives: row

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);
   }
}
Lastest update in May 2011, inital post in May 2011