private void deleteCollectorAgentEntriesToolStripButton_Click(object sender, EventArgs e) { if (!ShowTreeView) { if (lvwEntries.SelectedItems.Count > 0) { if (MessageBox.Show("Are you sure you want to delete the seleted entry(s)?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { foreach (ListViewItem lvi in lvwEntries.SelectedItems) { lvwEntries.Items.Remove(lvi); } } } } else if (tvwEntries.SelectedNode != null) { if (MessageBox.Show("Are you sure you want to delete the seleted entry(s)?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { TreeNode selectedNode = tvwEntries.SelectedNode; if (tvwEntries.SelectedNode.Tag is ICollectorConfigEntry) { tvwEntries.Nodes.Remove(selectedNode); } else { TreeNode parentNode = tvwEntries.SelectedNode.Parent; if (parentNode != null) { ICollectorConfigEntry entry = (ICollectorConfigEntry)parentNode.Tag; ICollectorConfigSubEntry subEntry = (from si in entry.SubItems where si.Description == selectedNode.Text select si).FirstOrDefault(); if (subEntry != null) { entry.SubItems.Remove(subEntry); } tvwEntries.Nodes.Remove(selectedNode); if (parentNode.Nodes.Count == 0) { tvwEntries.Nodes.Remove(parentNode); } } } } } }
private void deleteCollectorConfigEntryToolStripButton_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to delete the selected entry(s)", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { if (lvwEntries.Visible) { foreach (int index in (from int i in lvwEntries.SelectedIndices orderby i descending select i)) { ICollectorConfigEntry entry = (ICollectorConfigEntry)lvwEntries.Items[index].Tag; ICollectorConfig cnf = ((ICollectorConfig)currentEditingEntry.Collector.AgentConfig); cnf.Entries.Remove(entry); lvwEntries.Items.RemoveAt(index); } } else { ICollectorConfig cnf = ((ICollectorConfig)currentEditingEntry.Collector.AgentConfig); if (tvwEntries.SelectedNode.Nodes.Count > 0) { ICollectorConfigEntry entry = (ICollectorConfigEntry)tvwEntries.SelectedNode.Tag; cnf.Entries.Remove(entry); tvwEntries.SelectedNode.Nodes.Clear(); } else { ICollectorConfigEntry entry = (ICollectorConfigEntry)tvwEntries.SelectedNode.Parent.Tag; ICollectorConfigSubEntry subEntry = (from ent in entry.SubItems where ent.Description == tvwEntries.SelectedNode.Text select ent).FirstOrDefault(); if (subEntry != null) { entry.SubItems.Remove(subEntry); } } tvwEntries.Nodes.Remove(tvwEntries.SelectedNode); } currentEditingEntry.InitialConfiguration = currentEditingEntry.Collector.AgentConfig.ToConfig(); CheckOkEnabled(); } }