Results 1 to 8 of 8

Thread: ListView

  1. #1

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    ListView

    With theI am using the ListView control to display some files. How can I make them open by double-clicking them? The problem is not with opening them, but rather with detecting the double-click event.
    There is a double-click event for ListView, but it occurs when the control itself is double-clicked, not when individual items are clicked by the user. What should I do?
    I tried setting up a timer and seeing if the user clicks twice during a specific amount of ms, but it didn't work and is too un-professional
    What should I do?
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: ListView

    VB Code:
    1. Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     Static t As Single
    3.     Static itm As ListItem
    4.    
    5.     'ok the following test could be done better
    6.     'You could use GetTickCount istead of the Timer function
    7.     'and you can use the APIs to get the correct double click speed
    8.     If Timer - t < 0.5 Then
    9.         If Not ListView1.HitTest(x, y) Is Nothing Then
    10.             If Not itm Is Nothing Then
    11.                 If itm Is ListView1.HitTest(x, y) Then
    12.                     'Double Click has occured!
    13.                     MsgBox "Double Click"
    14.                 End If
    15.             End If
    16.         End If
    17.     End If
    18.     t = Timer
    19.     Set itm = ListView1.HitTest(x, y)
    20. End Sub

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: ListView

    What's wrong with doing it like this?

    VB Code:
    1. Private Sub ListView1_DblClick()
    2.     MsgBox ListView1.SelectedItem
    3. End Sub

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: ListView

    Quote Originally Posted by baja_yu
    What's wrong with doing it like this?

    VB Code:
    1. Private Sub ListView1_DblClick()
    2.     MsgBox ListView1.SelectedItem
    3. End Sub
    Nothing but the fact that you might not have double clicked on the selected item. You can double click outside of any item and the DblClick event will fire. My code ensures you double click on a specific item.

  5. #5

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: ListView

    Thanks!
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  6. #6
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: ListView

    Quote Originally Posted by Joacim Andersson
    Nothing but the fact that you might not have double clicked on the selected item. You can double click outside of any item and the DblClick event will fire. My code ensures you double click on a specific item.
    Yes, but still, when you double click it, it will select it on the first click, and the second one will fire the doubleclick event.

    The only downside I think is that if you doubleclick on empty space it will tirgger the code.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: ListView

    Quote Originally Posted by baja_yu
    The only downside I think is that if you doubleclick on empty space it will tirgger the code.
    That's just the point. But you might have many items in the listview. The first is selected, you've scrolled down (the selected item is not visible) and you double click on the side of one item which counts as a double click on an item that is not even visible. But of course if that doesn't matter go with it, I just answered your question "What's wrong with this"

  8. #8

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: ListView

    Yeah... that was what was happening Joacim.... thanks for the help!
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

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