Filling a ListBox from an array

MarkItZero

Freshman
Joined
Apr 10, 2003
Messages
43
Location
under the desk in my office
Hello again,

I am attempting to populate a listbox from an array I have created (thanks to the help of the good people on this board). I now wish to use this array to fill in the values of a listbox.

Here is what I have so far...

Code:
 'Declare Array and Datarow
        Dim ArryEquipment As ArrayList = New ArrayList()
        Dim RowEquip As DataRow

        'Fill Array
        For Each RowEquip In DsEquipment1.Tables("EstEquip").Rows
            If RowEquip("HeaderID") = HeaderID Then
                ArryEquipment.Add(New LookupItem(RowEquip("EstEquipID"), RowEquip("EquipCode").ToString()))
            End If
            lstEquipment.Items.Add(ArryEquipment)
        Next

        'Insert Fill ListBox Code

LookUpItem is a class which accepts two Items (ID,Text)

I thought the code to populate the list box would be something like...

Code:
Dim i as integer

For i=0 To RowEquip.Count -1
      lstbox.Items.Add(ArryEquipment)
Next

Of course the above code is totally wrong, but thats along the lines of what I was thinking.

Any Suggestions?

Thanks!
 
Or, to correct on your original for...next loop, here is how you could do it:

Visual Basic:
Dim i as integer

For i=0 To RowEquip.Count -1
      lstbox.Items.Add(ArryEquipment(i)) ' add (i) to specify that you want to add a specific array item to the listbox.
Next

Hope that helps.

--Sean
 
Actually, the better (I think) way to do that would be this (you would
use this if you wanted to selectively add the items, rather than just
all of them):
Visual Basic:
Dim d As String

For Each d In ArryEquipment
  ' If we should add this array item to the listbox then...
  lstbox.Items.Add(d)
  ' End If
Next
 
Back
Top