C#prevent从具有SubItemClicked Interering ItemChecked事件的一个ListView? [英] C# Prevent ItemChecked event on a ListView from Interering with SubItemClicked?

查看:167
本文介绍了C#prevent从具有SubItemClicked Interering ItemChecked事件的一个ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是就地编辑列表视图控制一个项目。

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

可编辑的列表视图增加​​了SubItemClicked事件让每一个细胞可以进行编辑。

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

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

我也有一个ItemChecked事件使列表视图复选框。

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

现在的问题是,一旦ItemChecked事件已启用任一行双击触发ItemChecked'事件和$ P $烧制而成pvents的SubItemClicked事件。

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:

在可能的解决办法是禁用列表视图的DoubleClickActivati​​on:

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

this.lstShuntData2.DoubleClickActivation = false;

的主要缺点在于,用户可能会发现在ListView有点过于灵敏,对任何点击鼠标。

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

推荐答案

.NET将专门添加此功能到ListView。不要问我为什么。

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

要摆脱它,听 NM_DBLCLK 反映通知,并在处理程序为做到这一点::

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;

这是那 ObjectListView 为解决众多问题之一您。即使你不使用整个项目,你可以看一下源$ C ​​$ C,并找出如何做自己的事情。

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.

这篇关于C#prevent从具有SubItemClicked Interering ItemChecked事件的一个ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆