c# - Remove duplicate items in the ListBox -


i need delete items in wpf listbox, use code :

while (listbox.selecteditems.count > 0) {   listbox.items.remove(listbox.selecteditem); } 

but problem listbox contains several same items, example :

chocolate milk orange milk banana apple milk 

if select 2nd occurence of milk @ 4th position , try delete given code, remove first occurence of milk @ 2nd position (not selected) , selected 2nd occurence of milk @ 4th position.

i have tried :

while (listbox.selecteditems.count > 0) {   listbox.items.removeat(listbox.items.indexof(listbox.selecteditem)); } 

but result same.

could give me clue on ?

try this

if (listbox.selecteditem != null) {    listbox.items.removeat(listbox.selectedindex); } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -