ListBox item actions

253 views Asked by At

I have a listbox with a list of items and I want to give them actions when clicked, unfortunately when I try to double click the listbox, the action is applied to the whole listbox and I'm not being able to find tips anywhere on how to give an action to each item on a listbox. In this case I want a click on an item on the listbox to display a youtube video on webbroswer1 So I've been asked to be less vague...I want to get each ITEM on a Listbox to navigate to a different webbrowser page. I have no more code than the one posted below...

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim curItem As String = ListBox1.SelectedItem.ToString()

    WebBrowser1.Navigate("http://www.youtube.com/embed/ECIupNr8U-o")

Someone able to help? Regards

1

There are 1 answers

0
OneFineDay On BEST ANSWER

If each item is a valid address then:

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
  If Not Listbox1.SelectedIndex = -1 Then
    WebBrowser1.Navigate(ListBox1.SelectedItem.ToString())
  End If
End Sub