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

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!