Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Using TreeView Control in C# 2.0 with checkboxes.
There are some Items in the TreeView.
There is a Button Control in my form.
What I need is when I click the Button it should Select all the Node-checkBoxes present in tree(Parent as well as child nodes).
Posted
Comments
Wendelius 8-Jan-12 10:47am    
Is this Forms, ASP.NET, WPF or something else?
[no name] 8-Jan-12 13:26pm    
c# 2.0, not asp.net, not wpf

1 solution

If this is forms, you can for example iterate through each root node and call a recursive method to check that node and it's children. For example:

Iteration:
C#
foreach (TreeNode node in treeView1.Nodes) {
   CheckItems(node);
}

Recursive method:
C#
private void CheckItems(TreeNode node) {
   node.Checked = true;
   foreach (TreeNode childNode in node.Nodes) {
      childNode.Checked = true;
      CheckItems(childNode);
   }
}
 
Share this answer
 
Comments
[no name] 8-Jan-12 13:25pm    
thanks for the reply.
this is really helpful.
Wendelius 8-Jan-12 13:32pm    
You're welcome :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900