Listbox (n00b question)

pruebens

Regular
Joined
Nov 21, 2002
Messages
71
How would I get the contents of a listbox to a variable

I try
Code:
dim var as string = me.listbox1.items


but that doesn't seem to work.
 
if you want only the selected item...
Visual Basic:
dim var as string = ListBox1.SelectedItem

this will get all selected items...
Visual Basic:
        Dim nCounter As integer
        Dim s As String

        For nCounter = 0 To ListBox1.Items.Count - 1
            If ListBox1.GetSelected(nCounter) = True Then
                s = s & ListBox1.Items(nCounter)
            End If
        Next
        label1.Text = s
this will get all items, even if they are not selected
Visual Basic:
        Dim nCounter As Short
        Dim s As String

        For nCounter = 0 To ListBox1.Items.Count - 1
            s = s & ListBox1.Items(nCounter)
        Next
        Label1.Text = s
 
Back
Top