#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    1
    Rep Power
    0

    VB.NET listview selected item text


    Hello,

    I am new to VB.NET. I have gone through some tutorials about VB.NET. However, I can't seem to figure out how to add a doubl click event to a Listview. Ie. when I double click on an item in the Listview I would like an event to occur. When I double click on the listview object all .NET will do is add, "ListView1_SelectedIndexChanged(...)" I want a ListView_DoubleClick(...) event instead. Does anyone know how to add a double click event to a listview object? Also, I am trying to find a function in listview that would return the string of the item selected in the listview box. It looks like VB.NET does not have a listview.selecteditem.text function like in VB 6. Any help would be greatly appreciated.

    Thanks,
    David
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    1
    Rep Power
    0
    Hi David,

    First you need to add a DoubleClick event handler you your ListView. In the code window, if you select your ListView from the left hand dropdown box and then select the 'DoubleClick' item in the right hand dropdown box, VB.NET will automatically create an empty DoubleClick event handler for you. This will allow you to code for a double-click on the ListView itself, however if you want to determine the actual item in the ListView that was double-clicked on, you will need to add some additional code to get the list view item that is under the mouse cursor...


    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    Dim objDrawingPoint As Drawing.Point
    Dim objListViewItem As ListViewItem

    objDrawingPoint = ListView1.PointToClient(Cursor.Position)

    If Not IsNothing(objDrawingPoint) Then
    With objDrawingPoint
    objListViewItem = ListView1.GetItemAt(.X, .Y)
    End With

    If Not IsNothing(objListViewItem) Then
    MsgBox(objListViewItem.Text)
    End If
    End If
    End Sub


    I hope this helps.

    Gary

    Comments on this post

    • Woodrow W Smith agrees : Thank you - this helped me with a similar vexation
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0
    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    Dim I As Integer
    For I = 0 To ListView1.SelectedItems.Count - 1
    MsgBox(ListView1.SelectedItems(I).Text)
    Next
    End Sub

    Comments on this post

    • LyonHaert disagrees : Please don't resurrect 4 year-old threads.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Thankxxxxx Brother


    Thankxxxxxx Brother for your kind help


    '-----------------------------------------------------------
    Originally Posted by megabitdk
    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    Dim I As Integer
    For I = 0 To ListView1.SelectedItems.Count - 1
    MsgBox(ListView1.SelectedItems(I).Text)
    Next
    End Sub

IMN logo majestic logo threadwatch logo seochat tools logo