vb.net 如何将数组列表放入列表框中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3355655/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:57:58  来源:igfitidea点击:

How do I put an arraylist in a Listbox

vb.netvisual-studio-2008

提问by HansEJC

So I need help on an assignment and I've been trying to solve it for more than a week, but I need help on putting an arraylist inside a listbox.

所以我需要一个作业的帮助,我已经尝试解决它一个多星期了,但我需要帮助将数组列表放入列表框。

That's what the GUI should look like in the end, all the information has to be saved in an arraylist; I should be able to add a new customer; click on a customer entry to edit it.

这就是 GUI 最终应该是什么样子,所有信息都必须保存在一个数组列表中;我应该能够添加一个新客户;单击客户条目进行编辑。

回答by FastAl

List1.Items.Clear
List1.Items.AddRange(al1.ToArray)

OR,

或者,

List1.Items.Clear
For each obj as object in al1
    List1.Items.Add(obj)
Next

Or,

或者,

List1.Items.Clear
For i as Integer = 0 to al1.count-1
    List1.Items.Add(al1(i))
Next 

You will have to override the ToString of your object in the Arraylist. You will have to make the listbox font a fixed font so you can do the spacing (Courier New).
I would suggest using a Generic.List (Of clsCustomer) however if that's not in the assignment you'll be stuck typecasting the objects in the arraylist.
This still leaves out a ton of detail for solving that assignment, however.
Good luck.

您必须在 Arraylist 中覆盖对象的 ToString。您必须将列表框字体设为固定字体,以便您可以设置间距(Courier New)。
我建议使用 Generic.List (Of clsCustomer) 但是如果这不在分配中,您将被困在对数组列表中的对象进行类型转换。
然而,这仍然遗漏了解决该任务的大量细节。
祝你好运。