Click here to Skip to main content
15,886,756 members
Articles / Desktop Programming / Windows Forms
Alternative
Tip/Trick

Select only one node in Treeview

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
3 Feb 2012CPOL 10.9K  
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)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --