Reputation: 25
I have a list Box that contains the names of several files. I can select a file name and click delete. The file will then be removed from my rackspace account. How do I automatically refresh the listBox with out restarting my application?
I have tried the following
listBox.refresh()
listBox.Update()
and neither give me the result I'm looking for.
Upvotes: 0
Views: 7232
Reputation: 460288
If you want to remove items from a ListBox
you have multiple options. You can reload the DataSource that you are using or you can simple remove them from the Items
by using ListBox.Items.Remove(item)
or ListBox.Items.RemoveAt(index)
.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(index);
// or
object item = listBox1.SelectedItem;
listBox1.Items.Remove(item);
}
Upvotes: 1