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?
- POSITION pos = plist-> getfirstselecteditemposition ();
- if (pos = = NULL)
- TRACE0 ( "No items were selected!\n");
- Else
- {
- While (POS)
- {
- int nitem = plist-> Getnextselecteditem (POS);
- Plist-> DeleteItem (Nitem);
- }
- }
But the actual test is not possible, such as
[CPP]View Plaincopyprint?
- First line of text
- Second line of text
- Third line of text
- Line Four text
If you choose, the remainder of the deletion is
[CPP]View Plaincopyprint?
- Second line of text
- 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?
- void Cmydlg::ondelreply ()
- {
- POSITION pos = m_listctrl.getfirstselecteditemposition ();
- if (pos = = NULL)
- {
- return;
- }
- Delreplywithposition (POS);
- }
- void CMyDlg::D elreplywithposition (POSITION POS)
- {
- int iitemindex = M_listctrl.getnextselecteditem (POS);
- if (pos! = NULL)
- {
- Delreplywithposition (POS);
- M_listctrl.deleteitem (iItemIndex);
- }
- Else
- {
- M_listctrl.deleteitem (iItemIndex);
- }
- }
Test Normal
Delete multiple lines of MFC list control (CLISTCTRL)