Click to See Complete Forum and Search --> : ewing


September 4th, 1999, 11:22 PM
vc50 mfc win95/98
I have what I am sure is a simple question. I have a populated ClistCtrl and I want to delete only the selected items. I figured I would traverse through the list and delete the items like so.
int i = GetNextItem( -1, LVNI_SELECTED);
while( i != -1 )
{
DeleteItem( i ) ;
i = GetNextItem( i, LVNI_SELECTED);
}
This does not work. All suggestions welcome and code fragments appreciated.

Gregory64
September 4th, 1999, 11:33 PM
Hi,
After you've deleted item indexses are changed, so if you have two selected item, one after another you will start search from selected item and skip it. Think about deleting item from end to start, you may use LVNI_ABOVE.

Hope it help

September 5th, 1999, 12:11 AM
Should I use a for loop or while loop. Can you please show me with a simple code fragment? Thank you for your time in advance.

Gregory64
September 5th, 1999, 12:41 AM
Ok, sure it isn't the best code, but two hours after midnight...

int index=m_List.GetItemCount()-1;
while (index!=-1)
{
index=m_List.GetNextItem(index,LVIS_SELECTED |LVNI_ABOVE);
m_List.DeleteItem(index);
}
index=rList.GetNextItem(-1,LVIS_SELECTED);//if last one was selected we miss it, now we got it
if(index!=-1)
m_List.DeleteItem(index);