Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Converting listbox items to a string.

  1. Sep 9, 2008 #1
    It seems like it would be a fairly simple task, yet I have been unable to complete this task.
     
  2. jcsd
  3. Sep 9, 2008 #2
    what language are you using?
     
  4. Sep 9, 2008 #3
    I'm using VB.
     
  5. Sep 9, 2008 #4
    try with Str(List1.List(x))
    where x = the item # you want. Remember it starts from 0
     
  6. Sep 12, 2008 #5
    That didn't work either. The error was that 'List is not a member of the 'Systems.Windows.Forms.ListBox'.

    I try this with no error but it's not converting the items to a single string:

    Dim OrigString As String = Me.lstLegend.Items.ToString()

    Essentially I need to convert all of the items in a list box to a single string which can then be processed through a function.

    Thanks, in advance.
     
  7. Sep 15, 2008 #6
    Private Sub Command1_Click()

    For x = 0 To 2
    Label1.Caption = Label1.Caption & CStr(List1.List(x))
    Next x

    End Sub

    That worked perfectly for me, try it. I had 3 items in my List.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?