HansEJC
HansEJC

Reputation: 87

How do I put an arraylist in a Listbox

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.

Upvotes: 4

Views: 32136

Answers (1)

FastAl
FastAl

Reputation: 6280

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.

Upvotes: 7

Related Questions