private void DeleteEvent_Click(object sender, EventArgs e) { if (selectedEventId == -1)//no item selected { MessageBox.Show("Select an event please !"); } else { MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this event ?", "Alert", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { if (databaseClass.DeleteEvent(selectedEventId)) { MessageBox.Show("Event deleted successfully!"); Refresh_Click(null, null); } else { MessageBox.Show("There were an error when trying to delete!"); } } else { //when cancel, unselect the selected button Button btn = new Button(); btn = (Button)FindName(selectedEventId.ToString()); btn.Background = new SolidColorBrush(Colors.Red); } } }