Adding Arraylist objects to listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wbosw
    New Member
    • Mar 2007
    • 36

    #1

    Adding Arraylist objects to listbox

    I have a Arraylist (SearchSkillsAr ray) that contains objects. I want to place those objects into a listbox. Here i'm using get enumerator to loop through the arraylist and add the objects to the listbox. I'm receiving the error Conversion from type 'SkillSearch' to type 'String' is not valid. Does anyone have any suggestion to fix this error?

    Thanks,
    wbosw



    SearchSkillsArr ay.Add(SkillSea rch)

    IterateUsingEnu merator(SearchS killsArray)


    Private Sub IterateUsingEnu merator(ByVal SearchSkillsArr ay As ArrayList)
    ListBox1.Items. Clear()
    Dim en As IEnumerator

    en = SearchSkillsArr ay.GetEnumerato r
    Do While en.MoveNext
    Me.ListBox1.Ite ms.Add(New ListItem(CType( en.Current, Object)))
    Loop

    End Sub
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    My first thought is that the ListBox control can only contain text. It seems as though you are trying to display an object in the ListBox which the ListBox will not accept unless you use the .ToString() method. I do not use the ListBox control very often though so I may be a bit off.

    Nathan

    Comment

    • wbosw
      New Member
      • Mar 2007
      • 36

      #3
      Thanks for the advice Nateraaaa

      Comment

      Working...