的WinForms ListView的 - 自动停止检查时,双击 [英] Winforms ListView - Stop automatically checking when double clicking

查看:180
本文介绍了的WinForms ListView的 - 自动停止检查时,双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做一个列表视图不会自动检查项目时,我双击它?

How do I make a listview not automatically check an item when I double click it?

我可以尝试挂钩到MouseDoubleClick事件,并选中属性设置为false,但感觉就像一个有点劈。我也办一个项目实际上是选中的时候相当昂贵的计算,并且不希望这个code上双击运行。通过上面的事件挂钩,该ItemCheck和放大器;鼠标双击处理之前ItemChecked引发事件。

I can try hooking into the MouseDoubleClick event, and set the Checked property to false, but that feels like a bit of an hack. I also run a reasonably expensive calculation when an item is actually checked, and don't want this code to run on a double click. With the event hooking above, the ItemCheck & ItemChecked events are raised before the double click is handled.

有一个高贵的解决这个?

Is there an elegent solution to this?

推荐答案

优雅是不是通常是跳转到心里时,你必须破解的方式,本机Windows控件的工作,但是这需要在这里什么字。一定要考虑,如果你真的想你的控制,从任何其他程序的列表视图不同的表现。

Elegant isn't typically the word that jumps to mind when you have to hack the way the native Windows control works, but that's what required here. Do consider if you really want your control to behave differently from the listviews in any other program.

添加一个新类到您的项目并粘贴下面所示的code。编译。从工具箱顶部的新控件到窗体中。

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

using System;
using System.Windows.Forms;

class MyListView : ListView {
    protected override void WndProc(ref Message m) {
        // Filter WM_LBUTTONDBLCLK
        if (m.Msg != 0x203) base.WndProc(ref m);
    }
}

这篇关于的WinForms ListView的 - 自动停止检查时,双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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