We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Pragmatically select children nodes when parent is selected

Hi, I need to be able to select all the children of a Node when a node has been selected. Something similar to the interactive checkbox functionality but without the checkboxes. Any suggestions. Thanks.

1 Reply

AD Administrator Syncfusion Team March 10, 2005 06:41 PM UTC

Hi Gurbhej, The best way to do this is to handle the AfterSelect event and then recursively add all of the selected nodes'' children to the selection. The following code snippet demonstrates this: private void treeViewAdv1_AfterSelect(object sender, System.EventArgs e) { TreeNodeAdvCollection tnc = new TreeNodeAdvCollection(); foreach (TreeNodeAdv n in this.treeViewAdv1.SelectedNodes) { this.AddChildren(tnc, n); } foreach (TreeNodeAdv n in tnc) { this.treeViewAdv1.SelectedNodes.Add(n); } } private void AddChildren(TreeNodeAdvCollection tnc, TreeNodeAdv n) { foreach (TreeNodeAdv child in n.Nodes) { tnc.Add(child); this.AddChildren(tnc, child); } } You''ll also need to set the SelectionMode to MultiSelectAll to allow a Node and its child to be selected simultaneously. Hope this helps. Regards, Gregory Austin Syncfusion Inc.

Loader.
Live Chat Icon For mobile
Up arrow icon