刷新列表框 vb.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23665980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
refresh a listbox vb.net
提问by user2120280
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?
我有一个包含多个文件名称的列表框。我可以选择一个文件名,然后单击删除。然后该文件将从我的 rackspace 帐户中删除。如何在不重新启动应用程序的情况下自动刷新列表框?
I have tried the following
我已经尝试了以下
listBox.refresh()
listBox.Update()
and neither give me the result I'm looking for.
并且都没有给我我正在寻找的结果。
回答by Tim Schmelter
If you want to remove items from a ListBoxyou have multiple options. You can reload the DataSource that you are using or you can simple remove them from the Itemsby using ListBox.Items.Remove(item)or ListBox.Items.RemoveAt(index).
如果您想从 a 中删除项目,ListBox您有多种选择。您可以重新载入数据源您正在使用,也可以从简单的删除它们Items使用 ListBox.Items.Remove(item)或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);
}

