private async void deletePrescriptions_Click(object sender, EventArgs e) { // Get the highlighted prescriptions in the prescriptionsGridView. DataGridViewSelectedRowCollection selectedRows = prescriptionsGridView.SelectedRows; // For each highlighted prescription, delete it. for (int i = 0; i < selectedRows.Count; i++) { // Get the PrescriptionID from the prescriptionsGridView row. int prescriptionID = (int)selectedRows[i].Cells["PrescriptionID"].Value; //// Get the Prescription entity. //Prescription prescription = GetPrescriptionEntity(prescriptionID); //// Delete the Prescription entity. //_db.Prescriptions.DeleteOnSubmit(prescription); // Delete the Prescription entity. try { await _client.DeleteAsync($"prescriptions/{prescriptionID}"); } catch { MessageBox.Show($"Unable to delete prescription id {prescriptionID} - please try again."); } } //// Save the changes to the database. //DoSave(); // Update the UI DisplayPrescriptions(); }