• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 693
  • Last Modified:

Check subnodes of treeview clicking parent node

Hi,

I have a treeview control with showcheckboxes = All  in my C# web application.

When i check on the parent node all its child nodes should be checked automatically. similarlly when i uncheck a parent node all its childnodes should be unckecked.

How can i do this?

0
annmampilly
Asked:
annmampilly
2 Solutions
 
burakiewiczCommented:
bool blnValue=true; // or false
foreach (TreeNode tn in selectedNode.ChildNodes)
                {
                    tn.Checked = blnValue;
                }

0
 
Babycorn-StarfishCommented:
something like this will get you started

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
    {
        SetSubNodesCheckState(e.Node, e.Node.Checked);
       
    }

    public void SetSubNodesCheckState(TreeNode root, bool isChecked)
    {
        if (root.ChildNodes.Count > 0)
        {
            for (int idx = 0; idx < root.ChildNodes.Count; idx++)
            {
                SetSubNodesCheckState(root.ChildNodes[idx], isChecked);
            }
        }
        root.Checked = isChecked;
    }
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now