protected void btnDelete_Click(object sender, EventArgs e)
{
// save the index of the first selected item so we can place the selection close
// to there after deleting.
Debug.Assert(m_lvCurrentMappingList.SelectedItems.Count > 0);
int firstSelected = m_lvCurrentMappingList.SelectedIndices[0];
// delete all of the selected items
foreach (ListViewItem item in m_lvCurrentMappingList.SelectedItems)
{
ImportMappingInfo mapping = (ImportMappingInfo)item.Tag;
m_lvCurrentMappingList.Items.Remove(item);
m_settings.DeleteMapping(MappingSet.Main, mapping);
}
// if there are items in the list...
if (m_lvCurrentMappingList.Items.Count > 0)
{
// restore the selection
if (firstSelected >= m_lvCurrentMappingList.Items.Count)
firstSelected = m_lvCurrentMappingList.Items.Count - 1;
m_lvCurrentMappingList.Items[firstSelected].Selected = true;
}
}