How to delete multiple items selected by the ListBox control (C #)

Source: Internet
Author: User
Today to a netizen buddy second big knife (http://dearymz.blog.163.com) Where to read the blog, saw him ask his questions to write a blog, and in Article Finally, I was touched by a blessing. I am the kind of person who is excited by others, so I wish him all the best.
The following is a solution for me:
By default, The ListBox control can only be selected. To select multiple items, you must set the selectionmode attribute to selectionmode. multisimple.

How can I capture this information if I want to delete multiple items selected by ListBox or perform other operations?

Private VoidButton_deleteselected_click (ObjectSender,EventargsE)

{

ListBox.SelectedindexcollectionSic = listbox_demo.selectedindices; // obtain the subscript of the selected item

If(Sic. Count =0)

Return;

Else

{

// Put the selected item in the list

List<Int> List =New List<Int> ();

For(IntI =0; I <SiC. Count; I ++)

{

List. Add (SiC [I]);

}

List. Sort (); // sort the list (the default sorting result in the library generally refers to sorting from bottom to big)

While(List. Count! =0) // Delete the selected item from The ListBox control in the ascending order of the subscript

// If other sequence is used here, the validity of the lower mark may be damaged.

{

Listbox_demo.items.removeat (list [list. Count-1]);

List. removeat (list. Count-1);

}

}

}

The following is a simple method for beginners:
Protected void removeappsclick (Object sender, eventargs E)
{

For (INT m = 0; m <listbox2.items. Count; m ++)
{
If (listbox2.items [M]. Selected)
Listbox2.items. Remove (listbox2.items [m]);
}
}

 

Related Article

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.