views:

22

answers:

1

I am using a in-place editable listview control for a project.

The editable listview adds a 'SubItemClicked' event so that each 'cell' can be edited.

lstSD2.SubItemClicked += new ListViewEx.SubItemEventHandler(lstSD2_SubItemClicked);

I also have the listview checkboxes enabled with a 'ItemChecked' event.

The problem is that once the 'ItemChecked' event is enabled double-clicking on any row fires the 'ItemChecked' event and prevents the 'SubItemClicked' event from firing.

Is there a way to enforce the need to actually 'check' the listview checkbox instead of firing whenever the row is double-clicked?

UPDATE1:

Once possible solution is to disable the listview's 'DoubleClickActivation':

this.lstShuntData2.DoubleClickActivation = false;

The main drawback to this is that the users may find the listview a little too sensitive to any mouseclick.

+1  A: 

.NET specifically adds this functionality to a ListView. Don't ask me why.

To get rid of it, listen for NM_DBLCLK reflected notification, and in the handler for that do this::

NativeMethods.NMHDR nmhdr = (NativeMethods.NMHDR)m.GetLParam(typeof(NativeMethods.NMHDR));

switch (nmhdr.code) {
case NM_DBLCLK:
    // The default behavior of a .NET ListView with checkboxes is to toggle the checkbox on
    // double-click. That's just silly, if you ask me :)
    if (this.CheckBoxes) {
        // How do we make ListView not do that silliness? We could just ignore the message
        // but the last part of the base code sets up state information, and without that
        // state, the ListView doesn't trigger MouseDoubleClick events. So we fake a
        // right button double click event, which sets up the same state, but without
        // toggling the checkbox.
        nmhdr.code = NM_RDBLCLK;
        Marshal.StructureToPtr(nmhdr, m.LParam, false);
    }
    break;

This is one of the many problems that ObjectListView solves for you. Even if you don't use the whole project, you can look at the source code and figure out how to do things yourself.

Grammarian