This article shows hot to expand only one Node per Level with JavaScript. Hook to the BeforeClientToggle event of the TreeView and handle it in the following way:
| Collapse previously expanded Node on the same Level |
Copy Code |
|
function BeforeClientToggle(node) { var parent = node.Parent; if (parent == null) { parent = node.TreeView; } var siblings = parent.Nodes; var siblingsCount = siblings.length; for (var nodeIndex = 0; nodeIndex < siblingsCount; nodeIndex++) { var siblingNode = siblings[nodeIndex]; if ((siblingNode != node) && (siblingNode.Expanded)) { siblingNode.Collapse(); return; } } } |
In summary, before a Node, that has child Nodes, is toggled we collapse the previously expanded sibling. This will leave only one Node expanded at a time per Level.