vb.net 删除列表框中的最后一项?VB 2008
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17727000/
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
Removing the last item in a listbox? vb 2008
提问by user2581791
I have a simple question. I have a listbox called listbox1. I want to add a button that removes the last item on the bottom whatever it maybe, when the button is clicked.
我有一个简单的问题。我有一个名为 listbox1 的列表框。我想添加一个按钮,当单击该按钮时,该按钮会删除底部的最后一个项目。
But I don't know how to finish it. something simple like listbox1.removeitem(some number?)
但我不知道如何完成它。一些简单的东西,比如 listbox1.removeitem(some number?)
What could I add to remove whatever item that is on the bottom on the list?
我可以添加什么来删除列表底部的任何项目?
回答by Alex
This will remove the last item in your ListBox. Using the RemoveAt method.
这将删除 ListBox 中的最后一项。使用 RemoveAt 方法。
ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1)
Using the RemoveAt method, we remove the item at the Index provided. Since we get the full length of items in your current ListBox (and subtract 1 because it is zero based) we get the last item.
使用 RemoveAt 方法,我们删除提供的索引处的项目。由于我们获得了当前 ListBox 中项目的全长(并减去 1,因为它是从零开始的)我们得到最后一个项目。

