tags:

views:

34

answers:

1

This code isn't working. It doesn't raise an exception or even do anything visible.

private void RemoveSelectedFiles()
{
    lstPhotos.Items.Remove(lstPhotos.SelectedItems);
}

How can I remove the selected items from a ListBox?

A: 

You have to remove one item at a time.

private void RemoveSelectedFiles()
{
    foreach (object item in lstPhotos.SelectedItems) 
        lstPhotos.Items.Remove(item);
}
Humberto