CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ewing

  1. #1
    Guest

    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.





  2. #2
    Join Date
    Aug 1999
    Posts
    427

    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


  3. #3
    Guest

    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.


  4. #4
    Join Date
    Aug 1999
    Posts
    427

    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
  •  





Click Here to Expand Forum to Full Width

Featured