ListView组标题单击 - 禁用Windows 7中的全选

dav*_*v_i 1 c# .net-3.5 windows-7

在XP中单击ListView的Group Header时,没有任何反应.在Windows 7中单击ListView的组头时,将选中该组中的所有项目.我无法在Windows Vista上测试,因为我没有机器.

如何通过单击Windows 7(或Vista中)中引入的组头来禁用"全选".

如果他们愿意,仍然允许用户选择多个甚至所有项目,而不是通过单击组头.

不建议使用替代ListViews(例如ObjectListView)的答案将不胜感激!

我没有使用WPF.

更新

作为测试,我尝试在ListView的鼠标添加事件中添加命中测试以查看是否单击了组标题以及是否要取消选择所有项目.

在XP中运行时,会执行所需的效果.在Windows 7中,它仍然会选择该组中的所有项目!

更新2

找到解决方案:看我的答案.

dav*_*v_i 6

我已经明白了.

希望有人会觉得这很有用 -

MSDN上的这个帖子中,有人试图创建一个单击组头的事件.我已经按照以下方式重新使用了它(请参阅如何定义函数和常量的链接):

public class MyListView : ListView
{
    //
    //some other code here, i.e. define constants, PInvoke, etc (see link)
    //

    protected override void WndProc(ref Message m)
    {
        //the link uses WM_LBUTTONDOWN but I found that it doesn't work
        if (m.Msg == WM_LBUTTONUP) 
        {
            LVHITTESTINFO info = new LVHITTESTINFO();

            //The LParamToPOINT function I adapted to not bother with 
            //  converting to System.Drawing.Point, rather I just made 
            //  its return type the POINT struct
            info.pt = LParamToPOINT(m.LParam);

            //if the click is on the group header, exit, otherwise send message
            if (SendMessage(this.Handle, LVM_SUBITEMHITTEST, -1, ref info) != -1)
                if ((info.flags & LVHITTESTFLAGS.LVHT_EX_GROUP_HEADER) != 0)
                    return; //*
        }
        base.WndProc(ref m);
    }
}
Run Code Online (Sandbox Code Playgroud)

这样可以识别点击次数,除非单击群组标题.如果你想要执行一些额外的功能,//*你可以放置一个事件等.

如果您需要更多功能,请使用switchon m.Msg而不是使用.ifWndProc