private void ButtonTimeDelete_Click(object sender, EventArgs e) { if (listViewTimes.SelectedItems.Count <= 0) { return; } var selectedListViewItem = listViewTimes.SelectedItems[0]; if (selectedListViewItem == null || !Guid.TryParse(selectedListViewItem.Tag.ToString(), out var id)) { return; } if (MessageBox.Show(this, @"Are you sure to delete time?", @"Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } try { TimeService.Delete(id); selectedListViewItem.Remove(); ChangeTimesFormStatus(FormStatusEnum.None); } catch (Exception exception) { ShowErrorMessage(exception.Message); } }