private void btnEdit_Click(object sender, EventArgs e) { ListViewItem item = this.listView1.SelectedItems[0]; frmLayerInfo info = new frmLayerInfo { LayerName = item.Text, MinScale = double.Parse(item.SubItems[1].Text), MaxScale = double.Parse(item.SubItems[2].Text) }; if (info.ShowDialog() == DialogResult.OK) { string[] strArray = new string[3]; strArray[0] = info.LayerName; if ((strArray[0] != item.Text) && this.LayerNameIsExist(strArray[0])) { MessageBox.Show("图层已存在"); } else { strArray[1] = info.MinScale.ToString(); strArray[2] = info.MaxScale.ToString(); item.Text = strArray[0]; item.SubItems[1].Text = strArray[1]; item.SubItems[2].Text = strArray[2]; XmlNode tag = item.Tag as XmlNode; for (int i = 0; i < tag.Attributes.Count; i++) { XmlAttribute attribute = tag.Attributes[i]; if (attribute.Name.ToLower() == "name") { attribute.Value = strArray[0]; } else if (attribute.Name.ToLower() == "minscale") { attribute.Value = strArray[1]; } else if (attribute.Name.ToLower() == "maxscale") { attribute.Value = strArray[2]; } } } } }
private void btnAdd_Click(object sender, EventArgs e) { frmLayerInfo info = new frmLayerInfo(); if (info.ShowDialog() == DialogResult.OK) { string[] items = new string[] { info.LayerName, info.MinScale.ToString(), info.MaxScale.ToString() }; if (this.LayerNameIsExist(items[0])) { MessageBox.Show("图层已存在"); } else { ListViewItem item = new ListViewItem(items); this.listView1.Items.Add(item); XmlNode newChild = this.CreateLayerNode(items[0], items[1], items[2]); item.Tag = newChild; this.m_pLayerSettingsNode.ChildNodes[0].AppendChild(newChild); } } }