Click here to Skip to main content
16,015,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using Treeview control and binding the tree view control with xml. I set the teeview property as ShowCheckBoxes=All. My requirement is on page load, treview control should select all the check boxes by default. i.e Checked is true. I request please help me out on this.

Thanks
Mahesh.
Posted

C#
foreach (TreeNode node in tv.Nodes)
{
node.Checked = true;
if(node.ChildNodes.Count > 0)
    checkChildNode(node);
}

private void checkChildNode(TreeNode node)
{
            foreach (TreeNode chNode in node.ChildNodes)
            {
                chNode.Checked = true;
                if (chNode.ChildNodes.Count > 0)
                    checkChildNode(chNode);
            }
}


If this helped you then please Vote and mark it as answer.
 
Share this answer
 
v2
Comments
Hiren solanki 11-Oct-10 10:02am    
good way to recursively check the node. have my +5.
USE THIS CODE


VB
For I As Integer = 0 To TreeView1.Nodes.Count
        TreeView1.Nodes(I).Checked = True
    Next


MAY HELP U...
PASS A COMMENT PLS...
 
Share this answer
 
Hi rajivlipu,

Using the above code, it selecting only the top node only. I need to select all the nodes i.e top to bottom nodes including childs. I Request can you help me on this.


Thanks
Mahesh.
 
Share this answer
 
This will checked your all nodes.

C#
foreach (TreeNode node in TreeView1.Nodes)
{
  node.Checked = true;
}


If this helped you then please Vote and mark it as answer.
 
Share this answer
 
Hi Mehta,

Thanks for update. Still i am not able to select all the nodes using of the above code. It is selecting only the top node. I request please help me out on this.


Thanks
Mahesh.
 
Share this answer
 

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