Winforms treeview, recursively check child nodes problem

后端 未结 1 1954
借酒劲吻你
借酒劲吻你 2020-12-05 14:48

The following code is taken direct from Microsoft at http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aftercheck%28VS.80%29.aspx.

  // U         


        
相关标签:
1条回答
  • 2020-12-05 15:27

    The .NET TreeView class heavily customizes mouse handling for the native Windows control in order to synthesize the Before/After events. Unfortunately, they didn't get it quite right. When you start clicking fast, you'll generate double-click messages. The native control responds to a double-click by toggling the checked state for the item, without telling the .NET wrapper about it. You won't get a Before/AfterCheck event.

    It's a bug but they won't fix it. The workaround is not difficult, you'll need to prevent the native control from seeing the double-click event. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox, replacing the existing one.

    using System;
    using System.Windows.Forms;
    
    class MyTreeView : TreeView {
        protected override void WndProc(ref Message m) {
            // Filter WM_LBUTTONDBLCLK
            if (m.Msg != 0x203) base.WndProc(ref m);
        }
    }
    
    0 讨论(0)
提交回复
热议问题