|
-
September 4th, 1999, 11:22 PM
#1
ewing
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.
-
September 4th, 1999, 11:33 PM
#2
Re: ewing
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
#3
RE: CListCtrl DeleteItem
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.
-
September 5th, 1999, 12:41 AM
#4
Re: RE: CListCtrl DeleteItem
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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|