0

So I am trying to code something in vb.net 2010 which will have a list box.

For example:

1) Apple 
2) Pizza
3) Juice

How would I display Line number 2 or any other to the user - I tried doing it with a label box like this Label1.Text = ListBox1.Text(2) - does not work.

2 Answers 2

2
Label1.Text = ListBox1.Items(1).ToString()

if you want to get the Text of the currently selected item then you can do

If ListBox1.SelectedItem IsNot Nothing
    Label1.Text = ListBox1.SelectedItem.ToString()
End If
Sign up to request clarification or add additional context in comments.

Comments

0
MsgBox("List box item 1: " & ListBox1.Items(0), MsgBoxStyle.Information)
MsgBox("List box item 2: " & ListBox1.Items(1), MsgBoxStyle.Information)
MsgBox("List box item 3: " & ListBox1.Items(2), MsgBoxStyle.Information)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.