.net - Check or uncheck all TreeViewItem children -


My project is WinForms, C #.

I have a checkbox with TreeView, which is set to true. There are several root nodes in which each has many children nodes.

I want to keep the nodes of all children in the same check / unchecked state as my parents, I have written the following event handler:

  Private zero Tree View 1_Afferture Check (Object Sender, Tree WeaveEventErgus E) {// In case of return, the event is inspired by the code given below (e.action == TreeViewAction unknown) {return; } System.Diagnostics.Debug.WriteLine (string.Format ("Checked - {0}", e.Node.Checked)); Foreach (TriNode subnode in e.Node.Nodes) {subnode.selected = E. Node Checked; }}  

However, it works very strange when clicking on the parent immediately, I can easily reproduce it by checking and unchecking the parent so that the subnode can Be tested, while parents are already uncontrolled.

How to do it more correctly?

This is a bug presented by the vista version of a native brideway control. It automatically toggles a check box and double click, but without first raising check and aftermarket events. The Windows Form Tree Weave Class Cover was not updated to handle this problem.

It is quite easy to decide, you need to stop the original control by seeing double-clicking. Add a new class to your project and paste the code shown below to compile.

  using the system;  
  Above the tool, leave the new control on your form. Using System.Windows.Forms; Public Class MyTreeView: Tree View (Protected Override Zero WndProc (Ref Messages)) {// Press WM_LBUTTONDBLCLK if (m.msg == 0x203) {m.Result = IntPtr.Zero; } And base. Weedproc (Ref M); }}  

Comments