private void cboSelectAction_SelectionChangeCommitted(object sender, EventArgs e) { switch (cboSelectAction.SelectedIndex) { case 0: // add new if (_loginForm.UserAccountId < 1) { throw new Exception("Login is required!"); } else { _pwTracker.InsertNewRecord(GetPasswordValues()); break; } case 1: // edit _pwTracker.EditEntry(GetPasswordValues()); break; case 2: // delete var id = (int)dv.Rows[dv.CurrentCell.RowIndex].Cells["Id"].Value; _pwTracker.DeleteEntry(id); break; } ClearSelection(); }
public void DeletePassword(DataGridView dataGrid) { var result = MessageBox.Show(@"Are you sure you want to delete the selection?", @"Deleting?", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result != DialogResult.Yes) { return; } try { var id = GetPasswordValues(dataGrid).ID; _pwTracker.DeleteEntry(id); MessageBox.Show(@"Record successfully deleted!", @"Record Deleted"); LoadDataGrid(dataGrid, false); } catch (Exception) { throw new Exception("Record not delete due to application error!"); } }