views:

265

answers:

1

I have a listbox which is bound to a generic list, whenever I removed an item from the generic list and rebind it to the listbox it still shows the deleted items. Here is the code :

            InventoryList.Remove(currInv);         
            lstSubMenu.ItemsSource = InventoryList;
            lstSubMenu.DisplayMemberPath = "InventoryItemName";

I checked the generic list and the item is being removed and there doesn't seem to be any errors in the output window.

+2  A: 

Set the ItemsSource = null before you set it to be InventoryList

However, it is generally better practice to set the ItemsSource property once and never again. You can do this by using an ObservableCollection. Once you do this you can add/remove to your heart's content and not have to worry about the binding target not getting updated.

markti