Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on windows phone app and I want to delete item from listbox.

I am using following code List numbers=new List();

 ObservableCollection<string> myCollection = new ObservableCollection<string>(numbers);
        int indexPerson = listBox1.SelectedIndex;
        myCollection.RemoveAt(indexPerson);
        var my = (ObservableCollection<string>)listBox1.ItemsSource;
        listBox1.ItemsSource=my;

and when I click on delete button one item is deleted based on index and then when I will delete another item the previously deleted item is show and current deleted item is deleted.

How can I delete all items?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
561 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want to clear all items you can just use

myCollection.ClearItems()

if you want to remove just selected item than use

 myCollection.Remove(Listbox1.Selecteditem)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...