Question

I have a list box ...my list box has multiple item..if i select multiple item i want to show multiple item the same time in message box ..my code like this:

cnt = LSTlocations.SelectedItems.Count
Dim list As New List(Of Integer)
Dim locid As Integer
 If cnt > 0 Then
        For i = 0 To cnt - 1
            Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
            locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
            list.Add(locid)
        Next

        For Each num In list
            MessageBox.Show("LocID:" & num)

        Next

now each time i am getting each value in message box..i want to get all value at same time..how i can do that?

Was it helpful?

Solution

You can join the list elements with String.Join() method instead of using a loop.

An example:

Dim list As New List(Of Integer) From {0, 1, 2, 3, 4, 5}

MessageBox.Show(String.Format("LocID: {0}", String.Join(", ", list)), _
                Nothing, MessageBoxButtons.OK, MessageBoxIcon.Information)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top