/// <summary> /// loops through monitees and removes selected monitees from listview and storage. /// </summary> private void RemoveListItem() { try { int increment = 0; if ((Lists.Items.Count > 0) && (Lists.SelectedIndices.Count > 0)) { ListViewItem[] selectedItems = new ListViewItem[this.Lists.SelectedIndices.Count]; if ((MessageBox.Show( "Are you sure you want to remove this entry?\nIt cannot be reversed.", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) { System.Collections.IEnumerator iEnum = Lists.SelectedIndices.GetEnumerator(); while (iEnum.MoveNext()) { selectedItems[increment] = Lists.Items[(Int32.Parse(iEnum.Current.ToString()))]; increment += 1; XMLDataList.RemoveFile(Lists.Items[(Int32.Parse(iEnum.Current.ToString()))].Text); } foreach (ListViewItem list in selectedItems) { Lists.Items.Remove(list); MoniteeList.RemoveMonitee(list.Text); } if (Lists.Items.Count == 0) { Lists.Items.Clear(); } HasChanged = true; } } else { Exceptions.Exception("unselectedremove"); } } catch (Exception ex) { MessageBox.Show("Having problems removing item\n" + ex, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void RemoveBtn_Click(object sender, EventArgs e) { try { int increment = 0; if ((destinationList.Items.Count > 0) && (destinationList.SelectedIndices.Count > 0)) { var selectedItems = new ListViewItem[destinationList.SelectedIndices.Count]; if ((MessageBox.Show( "Are you sure you want to remove this entry?\nIt cannot be reversed.", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) { var iEnum = destinationList.SelectedIndices.GetEnumerator(); while (iEnum.MoveNext()) { selectedItems[increment] = destinationList.Items[(Int32.Parse(iEnum.Current.ToString()))]; increment += 1; XMLDataList.RemoveFile(destinationList.Items[(Int32.Parse(iEnum.Current.ToString()))].Text); } foreach (var list in selectedItems) { destinationList.Items.Remove(list); MoniteeList.RemoveDestination(MoniteeList.FindMonitee(monitee.Name), list.Text); } if (destinationList.Items.Count == 0) { destinationList.Items.Clear(); } MonitorListView.HasChanged = true; } } else { Exceptions.Exception("unselectedremove"); } } catch (Exception ex) { MessageBox.Show("Having problems removing item\n" + ex, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }