views:

113

answers:

2

Hi I have this program Im trying to make

but now Im trying to add an option to delete items ( only the selected ones ).

thanx in advance

+1  A: 

To delete the selected items:

while (listBox1.SelectedIndices.Count > 0)
    listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
Jon Seigel
A good Smart One thanx jon
Tony
A: 
protected void Button2_Click(object sender, EventArgs e)
{
    for(int i = ListBox1.Items.Count -1; i>=0; i--)
    {
        if (ListBox1.Items[i].Selected)
        {
            ListBox1.Items.Remove(ListBox1.Items[i]);
        }
    }
}

This should work for deleting also

David L
listBox1.Items is an `ObjectCollection`. You're thinking of a `ListView`.
Jon Seigel
Error 1 'object' does not contain a definition for 'Selected'
Tony