How do I put an arraylist in a Listbox

前端 未结 1 838
甜味超标
甜味超标 2021-01-19 05:36

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

1条回答
  •  北海茫月
    2021-01-19 06:17

    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.

    0 讨论(0)
提交回复
热议问题