/// <summary> /// Edits the item template. /// </summary> private void EditTemplate(TsCDaItem template) { // prompt user to edit the template. TsCDaItem[] templates = new ItemListEditDlg().ShowDialog(new TsCDaItem[] { template }, IsReadItem, false); if (templates == null || templates.Length != 1) { return; } // get existing items without applying defaults. ArrayList items = new ArrayList(); foreach (ListViewItem item in itemListLv_.Items) { if (item.Tag != null && item.Tag.GetType() == typeof(TsCDaItem)) { if (item.Tag != mTemplate_) { items.Add(item.Tag); } } } // re-initialize the list with the new template. Initialize(templates[0]); // add items back. foreach (TsCDaItem item in items) { AddItem(item); } }
/// <summary> /// Edits a group of items. /// </summary> private void EditMI_Click(object sender, System.EventArgs e) { // check if the template if being editied. if (itemListLv_.SelectedItems.Count == 1) { if (itemListLv_.SelectedItems[0].Tag == mTemplate_) { EditTemplate(mTemplate_); return; } } // build list of items to edit (exclude template). ArrayList itemList = new ArrayList(itemListLv_.SelectedItems.Count); foreach (ListViewItem item in itemListLv_.SelectedItems) { if (item.Tag != null && item.Tag.GetType() == typeof(TsCDaItem)) { if (item.Tag != mTemplate_) { itemList.Add(item.Tag); } } } // prompt user to edit list of items. TsCDaItem[] items = new ItemListEditDlg().ShowDialog((TsCDaItem[])itemList.ToArray(typeof(TsCDaItem)), IsReadItem, false); if (items == null) { return; } // remove changed items. RemoveMI_Click(sender, e); // add changed items. foreach (TsCDaItem item in items) { AddItem(item); } }
/// <summary> /// Creates a new item. /// </summary> private void NewMI_Click(object sender, System.EventArgs e) { TsCDaItem template = null; // copy the current selection. if (itemListLv_.SelectedItems.Count > 0) { template = (TsCDaItem)((TsCDaItem)itemListLv_.SelectedItems[0].Tag).Clone(); } // prompt user to edit new item. TsCDaItem[] items = new ItemListEditDlg().ShowDialog(new TsCDaItem[] { template }, IsReadItem, true); if (items == null) { return; } // add new items. foreach (TsCDaItem item in items) { AddItem(item); } }