http://blog.csdn.net/vlily/article/details/7739483
Note: The fifth method has been tried, the rest has not tried, the feeling is right (the second method is wrong)
CListCtrl the selected row has two properties, if single selection is set to true, it can only be selected, otherwise it is multi-select (default).
Method One:
int Clistctrl::getselectionmark ();
Return value: Returns the selected index number, otherwise returns-1
Description: This function can handle the case of a single line, but with one drawback, it retains the last item you checked, so when you click on the blank, the last selected item is returned. This is why you need to be aware of this when using shortcut keys to delete operations, which can generally be combined with uintgetitemstate (int nitem,
UINT nmask) const; to judge.
Single line: int nitem = M_listctrl.getselectionmark ();
M_listctrl.deleteitem (Nitem);
Method Two:
This method is completely error!!!!!!!!!!!
Description: This can handle single-line and multirow (continuous) Cases
POSITION pos = m_listctrl.getfirstselecteditemposition (); if (pos = = NULL) {TRACE (_t ("No items were selected!\n"));} Else { while (POS) {int nitem = M_listctrl.getnextselecteditem (POS); m_ Listctrl.deleteitem (nitem); // You could does your own processing on nitem here }}
Method Three:
Description: Can handle single-row and multi-line cases, the individual generally use this method
while(M_listctrl.getnextitem (-1, Lvni_all | lvni_selected)! =-1){intNitem = M_listctrl.getnextitem (-1, Lvni_all |lvni_selected); M_listctrl.deleteitem (Nitem);} Method Four: Description: Can handle single-row and multi-line cases for(inti =0; I<m_listctrl.getitemcount (); i++){if(M_listctrl.getitemstate (i, Lvni_all | lvni_selected) = =lvis_selected) M_listctrl.deleteitem (i);} Method Five: POSITION sselpos=NULL; while(Sselpos =M_listctrl. Getfirstselecteditemposition ()) {intNselitem =-1; Nselitem=M_listctrl. Getnextselecteditem (Sselpos); if(Nselitem >=0&&nSelItem<M_listctrl. GetItemCount ()) {OK, this nselitem is our DD}}
CListCtrl multi-line deletion summary