如何将数组列表放入列表框中 [英] How do I put an arraylist in a Listbox

查看:38
本文介绍了如何将数组列表放入列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在一个任务上需要帮助,我已经尝试解决它一个多星期了,但我需要帮助将数组列表放入列表框.

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.

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

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.

推荐答案

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

或,

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

或者,

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

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

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.

这篇关于如何将数组列表放入列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆