Double-click beavior on a TreeNode checkbox

和自甴很熟 提交于 2020-01-03 15:57:40

问题


I have a TreeView populated with TreeNodes having icons and checkboxes.

I've been tryig to disable the checkig/unchecking ability of some of them discarding the event in the BerforeCheck method. This works fine, until I double click on the checkbox: the image of the checkbox is the opposite of its real state (it shows a check mark if the status is Checked=false). I've tried to fix that changing the StateImageIndex manually in the NodeDoubleClick and BeforeClick method with no success.

Even worse: I added a third image in the StateImageList (yes I want the checkboxes to be tri-state too) but I'm not using it yet (it's never set in my code), and the third image is set as the current state of the box after some double-click (at this point I can't determine a clear behavior).

How can I do to at best make it work as exepected, at worst disable the double-click on the checkbox? Thanks.

PS: The question has already been asked, but had no answer...


回答1:


Try this.. :) worked for me

public class NewTreeView : TreeView
    {
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x203)
                m.Result = IntPtr.Zero;
            else
                base.WndProc(ref m);
        }
    }


来源:https://stackoverflow.com/questions/5322391/double-click-beavior-on-a-treenode-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!