Delete multiple lines of MFC list control (CLISTCTRL)

Source: Internet
Author: User

http://blog.csdn.net/ccnyou/article/details/7841850

Search on the Internet, the results are not ideal, a lot of similar answers:

[CPP]View Plaincopyprint?
  1. POSITION pos = plist-> getfirstselecteditemposition ();
  2. if (pos = = NULL)
  3. TRACE0 ( "No items were selected!\n");
  4. Else
  5. {
  6. While (POS)
  7. {
  8. int nitem = plist-> Getnextselecteditem (POS);
  9. Plist-> DeleteItem (Nitem);
  10. }
  11. }


But the actual test is not possible, such as

[CPP]View Plaincopyprint?
    1. First line of text
    2. Second line of text
    3. Third line of text
    4. Line Four text



If you choose, the remainder of the deletion is

[CPP]View Plaincopyprint?
    1. Second line of text
    2. Line Four text



That is because after the first row is deleted, the second line becomes the first row, and then the second row is ready to be deleted and deleted to the original first row. Then I thought of one, recursive implementation, deleted from the back, will not be affected by the change:

[CPP]View Plaincopyprint?
  1. void Cmydlg::ondelreply ()
  2. {
  3. POSITION pos = m_listctrl.getfirstselecteditemposition ();
  4. if (pos = = NULL)
  5. {
  6. return;
  7. }
  8. Delreplywithposition (POS);
  9. }
  10. void CMyDlg::D elreplywithposition (POSITION POS)
  11. {
  12. int iitemindex = M_listctrl.getnextselecteditem (POS);
  13. if (pos! = NULL)
  14. {
  15. Delreplywithposition (POS);
  16. M_listctrl.deleteitem (iItemIndex);
  17. }
  18. Else
  19. {
  20. M_listctrl.deleteitem (iItemIndex);
  21. }
  22. }

Test Normal

Delete multiple lines of MFC list control (CLISTCTRL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.