//delete allergy private void button1_Click(object sender, EventArgs e) { ConnectDB EMRDatabase = new ConnectDB(); for (int i = 0; i < AllergyCBAllergy.Count(); i++) { EMRDatabase.RemoveAllergies(PatientInfo[2], AllergyCBAllergy[i], AllergyCBDoD[i]); } List <DataGridViewRow> toDelete = new List <DataGridViewRow>(); foreach (DataGridViewRow row in dataGridView1.Rows) { DataGridViewCheckBoxCell cell = row.Cells[2] as DataGridViewCheckBoxCell; if ((bool)cell.EditedFormattedValue == true) { toDelete.Add(row); } } foreach (DataGridViewRow row in toDelete) { dataGridView1.Rows.Remove(row); } dataGridView1.ClearSelection(); button1.Enabled = false; }