Silverlight, Dynamic Data collection, removing the contents of the dynamic collection itself

Source: Internet
Author: User
Tags silverlight

On the page of XAML, create a ListBox with x:name as _list1, where each entry in the listbox is ListBoxItem

if (_list1. SelectedItem = = NULL)//returns if the selected item of _list1 is empty
{
Return
}
Else
{
var list = _list1. selecteditems;//get all the selected items of _list1
list<listboxitem> outlist = new list<listboxitem> ();//Create a new collection to store all the ListBoxItem of the ListBox, and then manipulate the collection, Iterate over each item in this set, and if so, delete the item in the _list1.
foreach (ListBoxItem item in list)
{
Outlist.add (item);
}

foreach (ListBoxItem item in outlist)//Avoid removing yourself from the situation, as it involves changes in the dynamic set
{
if (item. Content.tostring ()! = "Attachment form")
_list1. Items.remove (item);
}
}

The overall equivalent of using an intermediate container

If the middle of this collection is not applicable, the collection may change during execution due to dynamic removal, resulting in an abnormal execution

Silverlight, Dynamic Data collection, removing the contents of the dynamic collection itself

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.