CListCtrl Multi-Line Delete summary

Source: Internet
Author: User

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

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.