DoubleClick a listview Item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsteiner
    New Member
    • Dec 2008
    • 25

    #1

    DoubleClick a listview Item

    Hi all
    I have a listview with checkboxes and I would like to catch the doubleclick event on an Item.
    Everything is o.k, BUT, the double clicking on the item, also checks/unchecks the checkbox of the item, which I don't want.

    Can I work around this ?

    Thanks In advance.
  • vekipeki
    Recognized Expert New Member
    • Nov 2007
    • 229

    #2
    You can create a derived class and override WndProc to bypass the WM_LBUTTONDBLCL K message:

    Code:
    public class MyListView : ListView
    {
        const int WM_LBUTTONDBLCLK = 0x203;
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_LBUTTONDBLCLK)
            {
                // raise the event
                this.OnDoubleClick(EventArgs.Empty);
    
                // but don't pass the message to base class
                return;
            }
    
            base.WndProc(ref m);
        }
    }
    Then open your Form.Designer.c s file and replace System.Windows. Forms.ListView with MyListView.

    There are also some custom open-source controls like ObjectListView, some of which are a bit friendlier to use than ListView, and you have the source to customize it further to your needs.

    Comment

    Working...