private void buttonAddChild_Click(object sender, EventArgs e) { // create new child XIMMappingItem item = _listViewCtrl.GetSelectedItem(); if (item == null || !XIMHelper.IsComplex(item.Element.Type)) { return; } FormElement frm = new FormElement(item.Element); if (frm.ShowDialog(this) != DialogResult.OK) { return; } XmlElement ele = frm.Element; // expand old child if (listViewMain.SelectedItems.Count > 0) { XmlListViewItem <XIMMappingItem> xitem = listViewMain.SelectedItems[0] as XmlListViewItem <XIMMappingItem>; xitem.Checked = true; } // check if child with the same name is exist List <XIMMappingItem> list = _listViewCtrl.GetCurrentList(); foreach (XIMMappingItem i in list) { if (i.Element.IsChildOf(item.Element) && i.Element.GetLastName() == ele.GetLastName()) { MessageBox.Show(this, "This element already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } // insert new child XIMMappingItem citem = new XIMMappingItem(ele); int index = list.IndexOf(item); list.Insert(index + 1, citem); // display new child _listViewCtrl.RefreshList(list); foreach (XmlListViewItem <XIMMappingItem> xi in listViewMain.Items) { if (xi.Item == citem) { xi.Selected = true; xi.EnsureVisible(); break; } } }
private void buttonAddElement_Click(object sender, EventArgs e) { // create new element XIMMappingItem item = _listViewCtrl.GetSelectedItem(); if (item == null) { return; } XmlElement tmp = item.Element.Clone(); tmp.XPath = item.Element.GetXDirectory(); FormElement frm = new FormElement(tmp); if (frm.ShowDialog(this) != DialogResult.OK) { return; } XmlElement ele = frm.Element; // check if element with the same name is exist List <XIMMappingItem> list = _listViewCtrl.GetCurrentList(); foreach (XIMMappingItem i in list) { if (i.Element.XPath == ele.XPath) { MessageBox.Show(this, "This element already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } // insert new child XIMMappingItem citem = new XIMMappingItem(ele); int index = list.IndexOf(item); list.Insert(index + 1, citem); // display new child _listViewCtrl.RefreshList(list); foreach (XmlListViewItem <XIMMappingItem> xi in listViewMain.Items) { if (xi.Item == citem) { xi.Selected = true; xi.EnsureVisible(); break; } } }