how do i create a function that executes when an item in a listbox is double clicked on? it has to be a double click on an item and not anywhere in the listbox. the item index or name has to be passed as an argument of the function.
thanks.
Printable View
how do i create a function that executes when an item in a listbox is double clicked on? it has to be a double click on an item and not anywhere in the listbox. the item index or name has to be passed as an argument of the function.
thanks.
Simply , like this :
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ListBox1.Items.AddRange(New String() {"marvinklein", "Edneeis", "Pirate"}) End Sub Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick Dim itm As String = Me.ListBox1.Text If itm <> "" Then 'Do your stuff here MsgBox("You doubleclicked " + Me.ListBox1.Text) Else Exit Sub End If End Sub
Updated ,
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ListBox1.Items.AddRange(New String() {"marvinklein", "Edneeis", "Pirate"}) End Sub Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick Dim itm As String = Me.ListBox1.Text If itm <> "" Then 'Do your stuff here ShowItem(Me.ListBox1.Text) [B]Me.ListBox1.SelectedIndex = -1[/B] Else Exit Sub End If End Sub Private Sub ShowItem(ByVal item As String) MessageBox.Show(item) End Sub