Example #1
0
        private void OnContactsDelete(object sender, EventArgs e)
        {
            //Get selected contact, if any
            var selected = _listContacts.SelectedItem as Contact;

            if (selected == null)
            {
                return;
            }

            //Display confirmation message
            if (MessageBox.Show(this, $"Are you sure you want to delete {selected.Name}?",
                                "Confirm Delete", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }

            try
            {
                _contacts.Remove(selected.Id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Contact not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            };

            BindContactList();
        }
Example #2
0
        private void DeleteContact()
        {
            var item = GetSelectedContact();

            if (item == null)
            {
                return;
            }

            if (MessageBox.Show("Are you sure you want to delete this Contact?",
                                "Delete Contact", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            _database.Remove(item.Name);
            RefreshContacts();
        }
        private void OnDelete(object sender, EventArgs e)
        {
            var item = GetSelectedContact();

            if (item == null)
            {
                return;
            }

            if (MessageBox.Show("Are you sure you want to delete " + item.Name + " ?",
                                "Delete Contact", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            _contactDatabase.Remove(item.Name);
            RefreshContacts();
        }