Results 1 to 13 of 13

Thread: [2005] Double click in empty ListView?

  1. #1

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    [2005] Double click in empty ListView?

    Hello everyone,

    I have a ListView control in Details view with columns and I want a file dialog to show when the user double clicks an empty part of the control. Problem is, the events DoubleClick and MouseDoubleClick are only triggered when an item is double clicked.
    So, is there an event that gets triggered when an empty part of the ListView control is (double) clicked?

    Thanks for any help,

    Alexander.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Double click in empty ListView?

    I don’t know of any event but it can be done by using apis. I have a class called GlobalMouseHook in my signature that you can use the double click event and determine if the click location is with in the listView control and then process your code.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    Once in a while I come across a post that I just want to figure out for the sake of doing it. Even if I never need to use the code myself, it just helps to fortify my knowledge.

    So I took a crack at this, and after a little digging, it turns out it was pretty simple to implement. You have to use an inherited listview class to accomplish this.

    VB Code:
    1. 'EXTENDED LISTVIEW TO PROVIDE DOUBLE CLICK NOTIFICATION WHEN
    2. 'DOUBLE CLICKING A BLANK AREA OF A LISTVIEW
    3. Public Class ListViewEx
    4.     Inherits ListView
    5.  
    6.     'EVENT THAT WILL FIRE WHEN THE BLANK AREA OF THE LISTVIEW IS DOUBLE CLICKED
    7.     Public Event DoubleClickBlankArea(ByVal sender As System.Object, ByVal e As System.EventArgs)
    8.  
    9.     'OVERRIDE THE WINPROC ROUTINE, SO WE CAN LOOK FOR SPECIFIC WINDOWS MESSAGES
    10.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    11.         'WE ARE NOT SUPPRESSING ANY MESSAGES, SO ITS FINE TO SEND
    12.         'ALL MESSAGES TO THE BASE CLASS FOR PROCESSING
    13.         MyBase.WndProc(m)
    14.  
    15.         'SINCE WE ONLY WANT THE NEW EVENT TO FIRE WHEN ITS
    16.         'IN THE BLANK AREA, CHECK 2 THINGS
    17.         '1) THAT NO ITEMS ARE SELECTED IN THE LISTVIEW
    18.         '2) THAT THE WINDOWS MESSAGE IS 515 (AKA &H203 or WM_LBUTTONDBCLK)
    19.         If Me.SelectedItems.Count = 0 And m.Msg = 515 Then
    20.             'RAISE THE EVENT UP TO THE CONTROL ON YOUR FORM
    21.             RaiseEvent DoubleClickBlankArea(Me, New EventArgs)
    22.         End If
    23.     End Sub
    24.  
    25. End Class

    VB Code:
    1. 'USAGE
    2.  
    3.     'NORMAL DOUBLECLICK THAT FIRES WHEN DOUBLE CLICKING AN ITEM
    4.     Private Sub ListViewEx1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewEx1.DoubleClick
    5.         MessageBox.Show("Item Double Clicked")
    6.     End Sub
    7.  
    8.     'NEW EVENT THAT FIRES WHEN DOUBLE CLICKING THE BLANK AREA OF LISTVIEW
    9.     Private Sub ListViewEx1_DoubleClickBlankArea(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewEx1.DoubleClickBlankArea
    10.         MessageBox.Show("Blank Area of " & DirectCast(sender, Control).Name & " Double Clicked")
    11.     End Sub

    It worked for the scenarios I tested (which were details view)

    Let me know how it works out for you.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Double click in empty ListView?

    Very sleek.
    Nice job, Kleinma....

  5. #5

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [2005] Double click in empty ListView?

    Sounds perfect!

    But how do I implement this new event into a ListView control?
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    all you do is add a new class to your project and call it ListViewEx

    copy the code from my post above into that and compile your project.
    (this will put the ListViewEx control into your toolbox so you can add it to forms)

    Then go back to your form, and replace your regular listview, with a ListViewEx control and you are all set.

  7. #7

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [2005] Double click in empty ListView?

    Strange...
    I have created the class, compiled the project and got the control in my toolbox, but when I try to add it to the form, Visual Studio terminates instantly...
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    I will create a demo project and upload it for you to see if that works for you.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    here you go.

    make sure when you open the sln file, the first thing you do is rebuild the project.
    Attached Files Attached Files

  10. #10

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [2005] Double click in empty ListView?

    This is proving to be harder than it should be...

    Now I get an error when compiling the project. The line:
    VB Code:
    1. If Me.SelectedItems.Count = 0 And m.Msg = 515 Then
    Gives a StackOverflowException, with no error data available.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    that is really odd.

    I know you are running .NET 2005, but what is the exact version? Did you install the VS.NET 2005 Service Pack 1?

    I ran this code on my machine with no errors at all.

    maybe a 3rd person could try it and see if it works for them. Then we can isolate the issue to something on your PC.

  12. #12

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [2005] Double click in empty ListView?

    I'm running Visual Studio 2005 Professional. (Exact version number: 8.0.50727.42)
    I haven't installed Service Pack 1, though. I will install it and try again.
    Last edited by arsmakman; Jan 25th, 2007 at 04:36 PM.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Double click in empty ListView?

    I am running 8.0.50727.762 (SP.050727-7600)

    I am also running WinXP SP2

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