private void editAddressItem() { tabControl.SelectTab("tabPageAddresses"); ListView.SelectedIndexCollection selectedItems = this.listViewAddresses.SelectedIndices; if (selectedItems != null && selectedItems.Count > 0) { AddressObject currentAddrObj = SettingsObject.ListAddress[selectedItems[0]]; AddressWindow window = new AddressWindow(currentAddrObj); DialogResult result = window.ShowDialog(); if (result == DialogResult.OK) { AddressObject newAddrObj = window.getAddressObject(); if (newAddrObj != null) { // Remove old object from collection SettingsObject.ListAddress.Remove(currentAddrObj); // Add new object to collection SettingsObject.ListAddress.Add(newAddrObj); // Remove old listview entry this.listViewAddresses.Items.RemoveAt(selectedItems[0]); // Add new listview entry ListViewItem item = new ListViewItem(new string[] { "", newAddrObj.AddressName, newAddrObj.AddressEMail }); item.Checked = newAddrObj.Active; this.listViewAddresses.Items.Add(item); this.listViewAddresses.Sort(); } } } }
private void addAddressItem() { tabControl.SelectTab("tabPageAddresses"); AddressWindow window = new AddressWindow(); DialogResult result = window.ShowDialog(); if (result == DialogResult.OK) { AddressObject addrObj = window.getAddressObject(); if (addrObj != null) { // Add to local collection SettingsObject.ListAddress.Add(addrObj); // Add to listview ListViewItem item = new ListViewItem(new string[] { "", addrObj.AddressName, addrObj.AddressEMail }); item.Checked = true; this.listViewAddresses.Items.Add(item); this.listViewAddresses.Sort(); } } }