Results 1 to 3 of 3

Thread: listbox doubleclick

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283

    listbox doubleclick

    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.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Simply , like this :
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Me.ListBox1.Items.AddRange(New String() {"marvinklein", "Edneeis", "Pirate"})
    3.     End Sub
    4.  
    5.     Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    6.         Dim itm As String = Me.ListBox1.Text
    7.         If itm <> "" Then
    8.             'Do your stuff here
    9.             MsgBox("You doubleclicked " + Me.ListBox1.Text)
    10.         Else
    11.             Exit Sub
    12.         End If
    13.     End Sub

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Updated ,

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e
    2. As System.EventArgs) Handles MyBase.Load
    3.         Me.ListBox1.Items.AddRange(New String() {"marvinklein", "Edneeis", "Pirate"})
    4.     End Sub
    5.  
    6.     Private Sub ListBox1_DoubleClick(ByVal sender As Object,
    7. ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    8.         Dim itm As String = Me.ListBox1.Text
    9.         If itm <> "" Then
    10.             'Do your stuff here
    11.             ShowItem(Me.ListBox1.Text)
    12.             [B]Me.ListBox1.SelectedIndex = -1[/B]
    13.         Else
    14.             Exit Sub
    15.         End If
    16.     End Sub
    17.  
    18.     Private Sub ShowItem(ByVal item As String)
    19.         MessageBox.Show(item)
    20.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width