Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Select only one node in Treeview

0.00/5 (No votes)
3 Feb 2012CPOL 11K  
Thanks, I am just changing False to True, And I got Automatically Check TreeView Child Nodes When Parent Is Checked.private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Checked) { ...
Thanks, I am just changing False to True, And I got Automatically Check TreeView Child Nodes When Parent Is Checked.

C#
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
       {
           if (e.Node.Checked)
           {
               //selectParentNodes(e.Node.Parent);
               selectChildNodes(e.Node.Nodes);
           }
           else
           {
               //DiselectParentNodes(e.Node.Parent);
               DiselectChildNodes(e.Node.Nodes);
           }
       }


C#
private void selectChildNodes(TreeNodeCollection childes)
       {
           foreach (TreeNode oneChild in childes)
           {
               if (oneChild.Checked==false)
                   oneChild.Checked = true;
               selectChildNodes(oneChild.Nodes);
           }
       }



C#
private void DiselectChildNodes(TreeNodeCollection childes)
       {
           foreach (TreeNode oneChild in childes)
           {
               if (oneChild.Checked)
                   oneChild.Checked = false;
               DiselectChildNodes(oneChild.Nodes);
           }
       }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)