Ejemplo n.º 1
0
        //Delete the currently selected User in Listview.
        private void BtnDeleteUser_Click(object sender, RoutedEventArgs e)
        {
            selectedUser = users[lstUserList.SelectedIndex];

            //DISPLAY A MESSAGEBOX TO CONFIRM DELETE.
            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete: " +
                                                      selectedUser.Username + "?", "Delete Confirmation",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    if (lstUserList.SelectedIndex != -1)
                    {
                        if (!UsersDB.DeleteSelectedUser(users[lstUserList.SelectedIndex]))
                        {
                            GetCurrentUser(selectedUser.UserID);
                        }
                    }
                    else
                    {
                        MessageBox.Show("No selection made, plz try again.", "Delete Btn Error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                PopulateListView();
            }
        }