In a program I'm working on right now I need to select any number of rows in a list control and remove them when the user presses a button, and destroy a CStringList object associated with each item. The problem is the darned things won't go away. I'm using the following handler:

void CIncludeDlg::OnRemdir()
{
CStringList* plSubDirs; // Pointer to a list of subdirectories
int nItem = -1; // Item index in the control


while ((nItem = m_lcIncludeList.GetNextItem(nItem, LVNI_ALL | LVNI_SELECTED)) != -1)
{
// Deallocate the associated stringlist object
plSubDirs = (CStringList*) m_lcIncludeList.GetItemData(nItem);

if (plSubDirs != NULL)
delete plSubDirs;

// Remove this item from the list control
m_lcIncludeList.DeleteItem(nItem);
}
}



When I attempt to remove more than one item from the list, only a few of them will actually disappear from the control. A run through the debugger seems to indicate that GetNextItem() is returning -1 somewhere in the middle of the selected items. Does anyone have an idea what's happening here?