ListBox in Vb.net application

mkgarg

Newcomer
Joined
Feb 9, 2005
Messages
2
Hi,

I have vb.net windows form.
I placed a listbox on form.
I want to select multiple items.

Now i want to add 2 item in this list box.
"Permanent" & "Temp"

If i select Permanent from form it should give me "A"
and if i select Temp it should return "B"

Please tell me how i can add these items into listbox.

Thanks
 
If all you wanted is to add both of those items into a listbox then...

[CS]listbox.items.add("Temp");
listbox.items.add("Permanent");[/CS]

If that's not what you wanted then I don't understand your question.
 
Also depending on how and where you want to access the listboxes selected item (or selected index)...

from clicking on the list box
Visual Basic:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Select Case ListBox1.SelectedItem
            Case "Temp"
                MessageBox.Show("Temp")
            Case "Permanent"
                MessageBox.Show("Permanent")
        End Select
    End Sub
or
Visual Basic:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
                MessageBox.Show(ListBox1.SelectedItem)
    End Sub
or from another control or function
Visual Basic:
Dim x As String
x = ListBox1.SelectedItem
or
Dim x as Integer
x = ListBox1.SelectedIndex
 
Back
Top