IE Treeview - Checking & Unchecking All Subnodes

  • Thread starter Thread starter Pat Roy
  • Start date Start date
P

Pat Roy

Hello...

I've created a treeview that looks something like:

Root
.....Folder1
.........Subfolder1A
.............File
.............File
.........Subfolder1B
.............File
.....Folder2
.........Subfolder2A
.............File
.........Subfolder2B
.............File
.............File

Each of the folders and files have the checkbox property turned on, so that everything but the root node has a checkbox. Now I need help with code the checks or uncheck all subfolders and files when a parent checkbox is checked or unchecked. Make sense?

So, for example, if the user checks Folder1's checkbox on, then all Folder1's subfolders and files need to have there checkboxes checked on.

I've been banging my head on this one and haven't figured anything out yet. Any help would be appreciated.
 
Not sure if you want C# or vb.net but the code (c#) I'm using is:

private void TreeView1_Check(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e){

TreeNode selectedNode =
TreeView1.GetNodeFromIndex(e.Node);

if (selectedNode.Nodes.Count>0){
foreach (TreeNode ChildNode in selectedNode.Nodes)
{ChildNode.Checked=selectedNode.Checked;}
}

}

If you want the vb code let me know and I'll translate.

Nicki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top