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]);
}
}