private void DeleteSelectedRows(DataGridView dataGridView) { foreach (DataGridViewCell cell in dataGridView.SelectedCells) { DataGridViewRow row = dataGridView.Rows[cell.RowIndex]; if (!row.IsNewRow) dataGridView.Rows.Remove(row); } }