• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

arraylist question

How can I list the items in an arraylist. I have an arraylist populated with integers and I'd like to display the values in a label...
0
acdagirl
Asked:
acdagirl
  • 3
  • 2
3 Solutions
 
jpaulinoCommented:
Here's a small example

        Dim myArray As New ArrayList()
        myArray.Add("one")
        myArray.Add("two")
        myArray.Add("tree")

        For x As Integer = 0 To myArray.Count - 1
            MsgBox(myArray(x).ToString)
        Next x
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Dim str As String
For Each i As Integer In YourArrayListNameHere
    If str = "" Then
        str = i
    Else
        str = str & "," & i
    End If
Next
YourLabelNameHere.Text = str
0
 
SanclerCommented:
Not frantically serious ;-)

    Private Function JoinList(ByVal al As ArrayList) As String
        Return Join(Array.ConvertAll(CType(al.ToArray(GetType(Integer)), Integer()), New Converter(Of Integer, String)(AddressOf IntegerToString)), ",")
    End Function

    Private Function IntegerToString(ByVal i As Integer) As String
        Return i.ToString
    End Function

    YourLabelNameHere.Text = JoinList(YourArrayListNameHere)

Roger
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Very pretty Roger!

Array.ConvertAll() is only available in VB.Net 2005 though...
0
 
SanclerCommented:
Yes, I know.  And I only recently discovered it, which is why I couldn't resist seeing if I could build a nice one-liner (forgetting the Convertor) with it.

But, as I said, it wasn't intended for real for this case.

Roger
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It could be done as a "one-liner" in C# with anonymous methods:
http://msdn2.microsoft.com/en-us/library/0yw3tz5k(VS.80).aspx
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now